(null) exception
Monkey Forums/Monkey Programming/(null) exception
| ||
I have a very peculiar exception issue. I have a background class like so: Class Tbackground Field myimage:Image Field r:Int, g:Int, b:Int Field xoffset:Int,yoffset:Int Field mywidth:Int Field myheight:int Method load(imagename:String) Print "entering load" myimage = LoadImage(imagename) mywidth=myimage.Width() myheight=myimage.Height() Print myheight 'DrawImage myimage, 0,0 End Method Method draw() Print "entering draw" PushMatrix Translate WIDTH/2,HEIGHT/2 'Rotate ticks/10.0 SetColor 128,128,128 Local x:Int=0 Local y:Int=0 x = (WIDTH)*-1 While x < WIDTH y = (HEIGHT)*-1 While y < HEIGHT DrawImage myimage, x, y y = y + myheight Wend x = x + mywidth Wend PopMatrix End Method End class This is tested in another app and works fine. My declaration for my instance is thus: Global background:Tbackground = New Tbackground I can call the load method background.load() and it apparently loads the image-- it prints the debug message "entering load" and then successfully prints the size of the image it loads so that appears to be happening correctly. But when I try to call background.draw(), I get the following error message: (null) Monkey Runtime Error : Memory access violation (Null) is orange. I've never seen this message before. It does not even get to the "entering draw" debug statement in the method-- it errors out before that. Any ideas? |
| ||
are you calling the background.draw() method from within OnRender() method of your app class? what target are you compiling for, does it work in html5? |
| ||
>are you calling the background.draw() method from within OnRender() method of your app class? Yes, but this should be irrelevant since it's not getting to the "entering draw" breakpoint. >what target are you compiling for, does it work in html5? I haven't tried it in HTML5 but it looks to me like this is some sort of error related to object methods. It will not work even if I remove the draw call from within the draw() method. |
| ||
I tried your code in a minimal mojo app and it worked fine in html5; calling the .load() method from OnCreate() and .draw() method from OnRender(), setting WIDTH and HEIGHT from OnCreate() as well. I think depending on the compiled target you might not get the print statement working if the whole method fails, but it could as well be somewhere else in the app not excluding the .load() method. Try a minimal mojo app in html5 with just the background class and single image, load image in OnCreate and draw in OnRender. Also, what are the image dimensions and extention? |
| ||
I was programming sort of fried out today, and the caffeine mix was not right. I'll hit it again tomorrow. If I keep running into the same error I will probably end up just rolling it all into a function instead of a class and forget about it for this app, it's just a singleton anyway. |
| ||
Running it under HTML5, I am getting the error "cannot read property f_device of (null)." This happens only if I am calling the draw method of the class. It appears that it's coming from DeviceHeight() and DeviceWidth(). It's strange because I can make these calls just fine in HTML5 from another app that uses the exact same background class and method. |
| ||
Make sure you're calling DeviceHeight and DeviceWidth from within a class that extends the mojo App class. Like in OnCreate(). Seems you can only use them once mojo has been initialized. |
| ||
That's right, I saw what I was doing-- I was calling them from my initial global declares. Now something else is happening, I will figure it out... |