Memory Access Violation
Monkey Forums/Monkey Beginners/Memory Access Violation
| ||
I've tried to start making my own game without following a tutorial, and every time i want to render an image using: DrawImage image 0,0 I get this error: Memory Access Violation I tried copy pasting code from some previous tutorials and I still got that... It also points me to this in the "graphics" class #If CONFIG="debug" DebugRenderDevice If frame<0 Or frame>=image.frames.Length Error "Invalid image frame" #End |
| ||
You didn't give us much information. Is the compiler crashing with that message or the game itself? If it's the game itself, is the game structured like the code below, which works just fine on 78a for me?Import mojo Function Main:Int() New ExampleGame() Return 0 End Class ExampleGame Extends App Method OnCreate:Int() SetUpdateRate(30) image = CreateImage(100, 100) End Method OnUpdate:Int() End Method OnRender:Int() Cls() DrawImage(image, 0, 0) End Field image:Image End |
| ||
This is the code that I have. Your code works for me. This is the error that I get: TRANS FAILED: Error executing './MonkeyGame', return code=15 ** BUILD SUCCEEDED ** Monkey Runtime Error : Memory access violation /Applications/MonkeyX77a/modules/mojo/graphics.monkey<450> /Users/alix_olliver/Documents/Programming/Monkey X/Shmup/Code/shmup.monkey<48> /Applications/MonkeyX77a/modules/mojo/app.monkey<65> STOPPED Done. |
| ||
What is the name of the file? Do you have a corresponding data folder? That's to say, for example if you have a file named 'mygame.monkey', a folder by the name 'mygame.data' needs to be in the same folder. In that folder is where the data should be, like 'ship.png'. That error is caused when the file isn't loaded. |
| ||
Oh. That fixed it. (awkward) |
| ||
Just for records keeping this might have been a problem that your image was not loaded properly. Right after your LoadImage line you can check if the your image is "Null". If that is the case it means that your image have not been loaded, and you can through an exception or printing it out in your console. This will at least give you a warning since your app will crash when it tries to draw it later on. |