Memory Access Violation
Monkey Forums/Monkey Programming/Memory Access Violation
| ||
Strict
Import mojo
Function Main:Int()
new XenoPop()
Return 0
End Function
Class XenoPop extends App
field bubble:Bubbles
Method OnCreate:Int()
bubble = New Bubbles
bubble.Create()
SetUpdateRate 60
return 0
End
Method OnRender:Int()
Cls(0,0,0)
For Local b:Bubbles = EachIn Bubbles.bubbleList
b.Render
Next
Return 0
End Method
Method OnUpdate:Int()
Return 0
End
End
Class Bubbles
Global bubbleList:List<Bubbles> = new List<Bubbles>
Global sm:Image = LoadImage("graphics/16bg.png", 1, Image.MidHandle)
Global me:Image = LoadImage("graphics/32bg.png", 1, Image.MidHandle)
Global la:Image = LoadImage("graphics/64bg.png", 1, Image.MidHandle)
Global xl:Image = LoadImage("graphics/128bg.png", 1, Image.MidHandle)
Field x:Float, y:Float
Field gravity:Float, bounceHeight:Float
Field direction:String
Field size:Int
Field image:Image
Method Create:Void()
Local b:Bubbles = New Bubbles
b.size = Rnd(1,4)
If b.size = 1
b.image = sm
b.bounceHeight = 3
b.gravity = 0.2
EndIf
If b.size = 2
b.image = me
b.bounceHeight = 6
b.gravity = 0.4
EndIf
If b.size = 3
b.image = la
b.bounceHeight = 9
b.gravity = 0.6
EndIf
If b.size = 4
b.image = xl
b.bounceHeight = 12
b.gravity = 0.8
EndIf
b.direction = "falling"
bubbleList.AddLast(b)
End Method
Method Render:Void()
DrawImage( image, x, y, 0 )
End Method
Method Update:Void()
End Method
End Class
Returning to monkey after a while of not using it I've tried to do a few things which went ok. Trying something new though and I get a Memory Access Violation with the code above when compiling to glfw. html5 throws a "null object" something. Can anybody help? |
| ||
| What is your project structure for your graphics? Remember they need to be in yourproject.data folder... |
| ||
| They are in the project data folder within a graphics directory. |
| ||
So it looks like this:
XenoPop\
XenoPop.monkey
XenoPop.data\
graphics\
16bg.png
32bg.png
64bg.png
128bg.png
? Also try wrapping the LoadImage command to something like this: Function MyLoadImage:Image(path:String, frames:Int, flag:Int) Local img:Image = LoadImage(path, frames, flag) if img = Null Then Error "Image is null "+path Return img End Function |
| ||
| The directory structure is as you have shown, also, when I try wrapping the LoadImage command in to that function I get the same thing. :/ Just going to do a quick test to see if having the image names starting with a letter instead of a number fixes it. Doubt it though! [edit]Nope, changing the names didn't make a difference" This is the output from the console! Memory access violation Monkey runtime error: Memory access violation C:/Apps/Coding/MonkeyPro56b/modules/mojo/graphics.monkey<133> C:/Apps/Coding/MonkeyPro56b/modules/mojo/graphics.monkey<278> E:/My Coding/Monkey/Xeopop/XeoPop/XeoPop.monkey<83> |
| ||
| Can you try loading your images with the flags and frame number? eg Global sm:Image = LoadImage("graphics/16bg.png", 1, Image.MidHandle) becomes Global sm:Image = LoadImage("graphics/16bg.png") What is on line 83 in your project? I guess its the Load Function? |
| ||
| Nope, get the same thing happening after trying that. Yes, on line 83 is the Load Function. I'm completely baffled! What about the space in the directory 'My Coding', could that be it? May aswell try and see what happens. |
| ||
| For Android, yeah the space will mess up the project... but I didnt think it would for HTML5. |
| ||
| Well, changing that to have no space in it never made any difference. I'm going to try loading the images in different ways to see if it makes a difference although the way I do it now shouldn't be a problem. :/ |
| ||
| I've just tried and got the same, and worked out why... Monkey doesnt like loading the images in the declaration, so try this: I'm doing the LoadImages now in the Constructor... |
| ||
Ah if you had it as this:
Field sm:Image = LoadImage("graphics/16bg.png", 1, Image.MidHandle)
Field me:Image = LoadImage("graphics/32bg.png", 1, Image.MidHandle)
Field la:Image = LoadImage("graphics/64bg.png", 1, Image.MidHandle)
Field xl:Image = LoadImage("graphics/128bg.png", 1, Image.MidHandle)
It would have worked straight away... but it should have worked with the Global too.... |
| ||
| Thanks! That worked! Lessons learned! |