Solution in last edit.
It actually did happen on my low end devices as well (GT-S5830
and GT-S5830i
).
The thing is, it did not happen because of low memory; I logged the current memory usage of my game and it did not cross 3 megabytes, when I had like 80 or more megabytes of free ram. I even ran System.gc()
consistently, which hints the garbage collector to free up some ram space.
I have no workaround but will update this answer as soon as I find one.
After some search, gpu related stuff (like textures) are not managed by the garbage collector (that's why they should be disposed manually). So calling System.gc()
is somehow pointless. Still, I'm disposing all of my textures, and the memory usage of my game is pretty low.
I tried all sorts of solutions and nothing worked BUT here is something that should fix the problem (haven't tried this one, but should work nonetheless):
Simply don't load so much textures over and over. My game used to dispose and then initialize all textures whenever the user navigated away from a screen. That is possibly causing the problem. What you need to do is to keep the loaded textures/texture atlases in memory (don't lose their reference). That way, navigating back to a screen wouldn't reload all the textures.
Avoid using raw Texture
s and instead use a POT (Power Of Two) TextureAtlas
.
I will apply these two steps to my project, and if the problem goes away, I'll come back to confirm my solution.
That wasn't the problem at all. I ran a really long loop of disposing and loading of textures, no exception/error was thrown. My above suggestion is not the solution. The problem is probably related to excessive Screen
switching, but I guess not since this problem also happens when changing the screen orientation repeatedly from portrait mode to landscape mode and vice versa.
Solution:
I thought that Game
's setScreen(screen)
calls Screen
's dispose()
automatically (which is not the case). dispose()
was used to dispose all of my underlying textures. I simply solved the problem by calling dispose()
in Screen
's hide()
overridden method.
Using TextureAtlas
s is very important because you reduce the amount of handles that are attached to each Texture
. (Which may be the reason of the EGL_SUCCESS error)
Tested on both GT-S5830
and GT-S5830i
(Samsung Galaxy Ace and Samsung Galaxy Y). Problem no longer occurs.