Crash from lack of graphics context?

Monkey Targets Forums/Android/Crash from lack of graphics context?

Raph(Posted 2013) [#1]
I've been dealing with multiple crashes upon the app starting up or resuming from suspend. These crashes only happen on Android.

Stuff like

fooImg:Image = LoadImage("foo.png")
foo.MidHandle()


crashing sometimes, because the image is null. Move the midhandling to later, and it works.

Or

loadingScreenImg:Image = LoadImage("loadingscreen.png")
DrawImage(loadingScreenImg, DeviceWidth()/2, DeviceHeight()/2)


Also because image is null.

That one I fixed by adding a Null check.

Now I have this one, which happened upon resuming the app I had just closed:



The offending code:

xpc = ui.X / DeviceWidth()


These all seem to have in common that stuff in the graphics system I would expect to be present at that point in execution isn't somehow... race condition or something?


Raph(Posted 2013) [#2]
I should add, I am using Monkey 70g.


muddy_shoes(Posted 2013) [#3]
Not sure what's going on with your image references. For example with the first one you say

crashing sometimes, because the image is null. Move the midhandling to later, and it works.


Which doesn't make much sense. If the reference is null after the load I don't see how it will gain a value at some point later. Also you reference "foo" where the declaration is "fooImg" and try to call MidHandle as a method, when that's a constant integer. I'm assuming that it's a completely fabricated example. Do you have an actual code snippet and the resulting error log?

That last one where you do give an error log is actually failing in Monkey's debug code which seems to have lost track of call depth. It may well be a bug, but it doesn't seem to have anything to do with images.


Raph(Posted 2013) [#4]
Sorry, those were pseudocode and I typo'd! Oops.

In the first example, I load the loading screen in OnCreate.



Then in OnUpdate I have:



That updateLoading() function loads images and sounds, etc. Works fine.

In OnRender, I draw the loading screen:



If I comment out the Null check for LoadingImg, the app crashes around 25% of the time on launch because loadingImg is Null. But the image is loaded in OnCreate().

The other example was very similar. I open the app after it has been closed, and it instantly crashes because it can't get DeviceHeight().

Basically, on resuming or first launch, it crashes a percentage of the time. The call stack is ALWAYS referencing something in graphics. Sometimes it's almost like the load is in a thread that hasn't returned yet? Or the graphics context is taking longer to initialize than the code takes to get going?

Here's another case where it just happened. I was in the app. I tapped the Home button on the device. I relaunched the app after maybe 15 seconds, and got this:



This time it's in DrawImageRect().


muddy_shoes(Posted 2013) [#5]
That crash still isn't about an image reference. It's inside the Vector.remove call from Monkey's popErr. If you build in release mode it should go away (or maybe just reveal a more relevant error).

I'm curious why it's crashing there though. I wonder if there's a bug in the Apache standard lib implementation.


Raph(Posted 2013) [#6]
So it is. In fact, it just happened again! And this time, the app had been closed for a good while and the device had even gone to sleep. Tapped to launch and got the same array index error:




muddy_shoes(Posted 2013) [#7]
Seems odd that you find it so easy to reproduce. I don't recall anyone reporting it and I can't reproduce with my own code. I can't see anything obviously wrong in the Monkey popErr stuff or in the Apache lib implementation: https://android.googlesource.com/platform/libcore/+/master/luni/src/main/java/java/util/Vector.java

Did you try with release mode to see if the problems disappear?


Raph(Posted 2013) [#8]
One more from debug mode:



I can't get it to happen in release.


muddy_shoes(Posted 2013) [#9]
Time to maybe point Mark at this thread and/or testing the debug-mode apk on different devices to see if it's specific to something about your setup. I'm happy to try it on my phone if you're okay with providing the apk (probably not until tomorrow though NZ time).