V69 - FATAL EXCEPTION: GLThread 11

Monkey Targets Forums/Android/V69 - FATAL EXCEPTION: GLThread 11

sionco(Posted 2013) [#1]
Hi
I can compile all of my games using version 66b,
but when I try to compile these games (very basic games work) with version 69 or 70, I get the following errors:

Starting: Intent { cmp=com.optima.EnglishSounds2/.MonkeyGame }
--------- beginning of /dev/log/main
--------- beginning of /dev/log/system
E/SensorManager( 8448): registerListener :: handle = 0  name= BMA220 delay= 20000 Listener= com.optima.EnglishSounds2.BBMonkeyGame@4052c5f0
E/SensorManager( 8448): =======>>>Sensor Thread RUNNING <<<========
E/SensorHAL(  189): +__poll_activate: handle=0 enabled=1
E/SensorHAL(  189): > Accelerometer Write /sys/class/input/input3/enable 1
E/SensorManager( 8448): reg :: handle = 0
E/AndroidRuntime( 8448): FATAL EXCEPTION: GLThread 11
E/AndroidRuntime( 8448): java.lang.NullPointerException
E/AndroidRuntime( 8448): 	at com.optima.EnglishSounds2.BBAndroidGame.LoadBitmap(MonkeyGame.java:1134)
E/AndroidRuntime( 8448): 	at com.optima.EnglishSounds2.gxtkGraphics.LoadSurface__UNSAFE__(MonkeyGame.java:1600)
E/AndroidRuntime( 8448): 	at com.optima.EnglishSounds2.gxtkGraphics.LoadSurface(MonkeyGame.java:1607)
E/AndroidRuntime( 8448): 	at com.optima.EnglishSounds2.bb_graphics.g_LoadImage(MonkeyGame.java:3368)
E/AndroidRuntime( 8448): 	at com.optima.EnglishSounds2.bb_resources.g_LoadButtons(MonkeyGame.java:3164)
E/AndroidRuntime( 8448): 	at com.optima.EnglishSounds2.c_TheSoundsOfEnglish.p_OnCreate(MonkeyGame.java:2544)
E/AndroidRuntime( 8448): 	at com.optima.EnglishSounds2.c_GameDelegate.StartGame(MonkeyGame.java:2626)
E/AndroidRuntime( 8448): 	at com.optima.EnglishSounds2.BBGame.StartGame(MonkeyGame.java:509)
E/AndroidRuntime( 8448): 	at com.optima.EnglishSounds2.BBAndroidGame.onDrawFrame(MonkeyGame.java:1241)
E/AndroidRuntime( 8448): 	at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1388)
E/AndroidRuntime( 8448): 	at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1138)
E/        (  189): Dumpstate > /data/log/dumpstate_app_error


I'd really like to use the newer versions of monkey as they include things like OpenUrl

I've had a look through the forum, and can't find a similar problem.

thanks


Nobuyuki(Posted 2013) [#2]
Hi,

This is just a shot in the dark, but on v67+, don't check for returns on invalid file handles to be Null. For some reason, on Android, if you try to load a file that isn't there using LoadImage, it crashes with NullPointerException immediately -- you can't "catch" this error by checking for Null, not even on the very next line.

The major culprit behind my app having this error was AngelFont, which relies on the assumption that invalid file loads can be checked for null afterwards without a runtime error. Your code might be crashing in a subroutine called "LoadButtons" , or simply in OnCreate for the above reasons (ie: trying to load an image from an invalid location).


sionco(Posted 2013) [#3]
Many Thanks for your help!

it's definitely something about loading images or files by passing string names, for example, I have a function in another .monkey file to load all the images I need.
The first example causes the error in the versions of monkey since v67:
Function LoadButtons()

	For Local i:Int = 1 To 44
		imgButtons[i] = LoadImage(String("buttons/"+i+".png"))
	Next
End


but if I load each file individually:

Function LoadButtons()

imgButtons[1] = LoadImage("1.png")
	imgButtons[2] = LoadImage("2.png")
	imgButtons[3] = LoadImage("3.png")
	imgButtons[4] = LoadImage("4.png")
	imgButtons[5] = LoadImage("5.png")
	imgButtons[6] = LoadImage("6.png")
	imgButtons[7] = LoadImage("7.png")
	imgButtons[8] = LoadImage("8.png")
	imgButtons[9] = LoadImage("9.png")
	imgButtons[10] = LoadImage("10.png")
	imgButtons[11] = LoadImage("11.png")
	imgButtons[12] = LoadImage("12.png")
End


it works.

I also replaced angelfont with font machine.

Another case was that I was passing a string to a function that loaded the contents of a file.

if I passed the string to the function, for example:
Method LoadTrack(filename:String)
 Local file:TextFile
 file = New TextFile(filename)

it wouldn't work, however:

Method LoadTrack()
  Local file:TextFile
   file = New TextFile("track01.txt")


works.

This will make it a little less friendly to program (unless I doing it wrong?)


marksibly(Posted 2013) [#4]
> For some reason, on Android, if you try to load a file that isn't there using LoadImage, it crashes with NullPointerException immediately

Just gave this a quick test, and LoadImage with 'bad' image paths seems to be working OK, ie: it returns Null instead of crashing.

> but if I load each file individually:

Well, in your example you're loading 2 different sets of images - one from 'buttons/', the other not.

But in general, there's no reason why loading an image from a 'constant' path should work any differently to loading an image from a 'variable' path - check your code!


Nobuyuki(Posted 2013) [#5]
>Just gave this a quick test, and LoadImage with 'bad' image paths seems to be working OK, ie: it returns Null instead of crashing.

Huh. That's weird, because the problem I had was when I upgraded to v69, and the stack trace pointed to a very specific part of AngelFont (which shouldn't exhibit this behavior under normal usage, especially seeing as how it comes with Monkey), line 181:




Pagecount is basically a value AngelFont checks to see if it's an "Old" BMFont file without paged filenames. If it is, it first tries to load the file without a page extension, and then checks if the file came back Null, and if so, to use the new format instead. The specific part where my app crashed on Android after moving to v69 was the line image[0] = LoadImage(url+".png"), whereas the Else block doesn't crash despite the fact the original block is supposed to eventually load the same exact file (ie: with a _0 appended). Commenting out most of the code block and only leaving the code inside the Else part (ie: the file format for new BMFont exports) made the code work again. There's no way that url could be different for the two tests, so I concluded it was a problem with LoadImage() returning Null on Android...


skid(Posted 2013) [#6]
After having a look at LoadBitmap I can see where it could fail.

In androidgame.java if OpenInputStream returns a Null (if path starts with monkey://data/) then LoadBitmap is going to crash as it is expecting an IOException not a null return.


Earok(Posted 2013) [#7]
I was having the same issue, though Monkey V70 seems to have resolved it.