www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: AeroShark333 on January 21, 2015, 05:38:51 pm

Title: EGL_BAD_ALLOC error
Post by: AeroShark333 on January 21, 2015, 05:38:51 pm
Hello everyone,

I hope I can get some help with an odd error.
I am getting this error a lot lately in the Google Developers Console:
Code: [Select]
java.lang.RuntimeException: eglSwapBuffers failed: EGL_BAD_ALLOC
at android.opengl.GLSurfaceView$EglHelper.throwEglException(GLSurfaceView.java:1077)
at android.opengl.GLSurfaceView$EglHelper.swap(GLSurfaceView.java:1035)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1333)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1116)

I got three reports of this error.
I found it odd that all three reports came from Android 2.2 devices.
Devices:
Galaxy Mini (GT-S5570)
IDEOS S7 Slim (qsd8k_slim)
Galaxy Precedent (SCH-M828C)

I hope that I can get some help with this error! :)

Cheers,
Abiram
Title: Re: EGL_BAD_ALLOC error
Post by: EgonOlsen on January 21, 2015, 06:19:35 pm
Google finds this (among other hints):http://stackoverflow.com/questions/9293241/eglswapbuffers-failed-egl-bad-alloc-andengine-android (http://stackoverflow.com/questions/9293241/eglswapbuffers-failed-egl-bad-alloc-andengine-android). Maybe that helps.
Title: Re: EGL_BAD_ALLOC error
Post by: AeroShark333 on January 21, 2015, 11:17:30 pm
I mainly found that adding (instance GLSurfaceView).onPause() and (instance GLSurfaceView).onResume() should work in the Overridden methods of Activity. However, I already have those...
Title: Re: EGL_BAD_ALLOC error
Post by: AeroShark333 on January 22, 2015, 07:48:45 am
Update.

New error:
Code: [Select]
java.lang.RuntimeException: eglSwapBuffers failed: EGL_BAD_ALLOC
at android.opengl.GLSurfaceView$EglHelper.throwEglException(GLSurfaceView.java:1229)
at android.opengl.GLSurfaceView$EglHelper.swap(GLSurfaceView.java:1187)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1514)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1267)
But this time it is not on Android 2.2, but Android 4.0.3 - 4.0.4.
Device: nuclear-XIONhh901

I couldn't find anything about this device.
However, the Android 2.2 devices all had an Andreno 200 GPU (if that matters)...
Title: Re: EGL_BAD_ALLOC error
Post by: EgonOlsen on January 22, 2015, 08:05:18 am
Does this happen at startup or randomly at runtime...or when? It's clearly something on your side, because jPCT-AE just renders into a gl context. It doesn't care about any buffer swapping and such and it doesn't trigger anything in that regard.
Title: Re: EGL_BAD_ALLOC error
Post by: AeroShark333 on January 22, 2015, 11:53:07 am
I really do noy have a clue...
The Play Store doesn't give more information tham that.
Any other suggestions?
Title: Re: EGL_BAD_ALLOC error
Post by: EgonOlsen on January 22, 2015, 12:38:23 pm
Not really. If that's all you get as debug information, it's hard to make something out of it. Maybe it's related to memory? It might be worth a  try to add "android:largeHeap" to your manifest (in case you haven't already) and see if that helps, but other than that, it's hard to fix this (if it's even possible) without an actual device that allows you to reproduce this error.
Title: Re: EGL_BAD_ALLOC error
Post by: AeroShark333 on January 22, 2015, 02:53:31 pm
Hmm, I can add android:largeHeap="true"
However, I do not think that would fix the error on Android 2.2 devices.
Why? Because the largeHeap feature is added in API Level 11.
Android 2.2 (API Level 8 ) would ignore that line, since it's function is known.
Title: Re: EGL_BAD_ALLOC error
Post by: EgonOlsen on January 22, 2015, 04:54:22 pm
I wasn't sure when it was added...it won't help then.
Title: Re: EGL_BAD_ALLOC error
Post by: AeroShark333 on February 07, 2015, 09:34:34 pm
java.lang.NullPointerException
at com.threed.jpct.GLRenderer.setTextures(GLRenderer.java:2441)
at com.threed.jpct.GLRenderer.drawVertexArray(GLRenderer.java:2297)
at com.threed.jpct.World.draw(World.java:1417)
at com.threed.jpct.World.draw(World.java:1100)
at com.aeroshark333.skinviewer.SkinActivity$ViewerRenderer.onDrawFrame(SkinActivity.java:1048)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1401)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1146)

How does this happen?

line 1048: [mainWorld.draw(frameBuffer);]
Title: Re: EGL_BAD_ALLOC error
Post by: EgonOlsen on February 07, 2015, 10:12:31 pm
Most likely because you are fiddling around with something jPCT related in some other than the rendering thread, like changing textures in an async way or in an event listener.
Title: Re: EGL_BAD_ALLOC error
Post by: EgonOlsen on February 07, 2015, 10:13:54 pm
http://www.jpct.net/wiki/index.php/Nullpointer_during_rendering_and/or_collision_detection (http://www.jpct.net/wiki/index.php/Nullpointer_during_rendering_and/or_collision_detection)
Title: Re: EGL_BAD_ALLOC error
Post by: AeroShark333 on February 08, 2015, 12:55:57 am
So passing "Runnable"s to the GLSurfaceView thread should solve my problem, right?

Edit: Using GLSurfaceView.queueEvent(Runnable r);
Title: Re: EGL_BAD_ALLOC error
Post by: EgonOlsen on February 08, 2015, 09:13:27 am
That's one solution...at least if something like this really causes your problem.
Title: Re: EGL_BAD_ALLOC error
Post by: AeroShark333 on February 14, 2015, 12:29:35 pm
A bit offtopic but is it possible to bend an Object3D.
For instance, let's say I have an cube object (uv mapped). Is it possible to curve/bend it so there probably will be more vertices, but it still has the appropriate texture on each cube face. Bend/curve = making a cube a bit 'U' shaped for example.

Sorry for this question, I am very noob at OpenGL related stuff :/
Title: Re: EGL_BAD_ALLOC error
Post by: EgonOlsen on February 15, 2015, 09:03:29 pm
You need another model with more vertices then. You actually can't bend anything but a vertex. If there's no additional vertex between point A and B, the connection between them will always be a line.
Title: Re: EGL_BAD_ALLOC error
Post by: AeroShark333 on March 23, 2015, 05:10:43 pm
Hmm okay...

Another problem (offtopic again, sorry):

I sometimes get this crashreport, but I don't know why most people don't get it...:
Code: [Select]
java.lang.RuntimeException: [ 1427084178793 ] - ERROR: Failed to load and compile fragment shaders!
at com.threed.jpct.Logger.log(Logger.java:206)
at com.threed.jpct.GLSLShader.loadProgram(GLSLShader.java:1077)
at com.threed.jpct.GLSLShader.preInit(GLSLShader.java:285)
at com.threed.jpct.GL20.setShader(GL20.java:362)
at com.threed.jpct.GLRenderer.setShader(GLRenderer.java:553)
at com.threed.jpct.CompiledInstance.render(CompiledInstance.java:189)
at com.threed.jpct.GLRenderer.drawVertexArray(GLRenderer.java:2308)
at com.threed.jpct.World.draw(World.java:1417)
at com.threed.jpct.World.draw(World.java:1100)
at com.aeroshark333.skinviewer.SkinActivity$ViewerRenderer.onDrawFrame(SkinActivity.java:1522)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1368)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1123)

This error occured for my users on:
Android 4.4: 5x
Android 4.3: 1x
Android 2.3.x: 9x

Fragment shader:
Code: [Select]
precision highp float;

uniform sampler2D textureUnit0;

varying vec2 texCoord;
varying vec4 vertexColor;

void main() {
gl_FragColor= texture2D(textureUnit0, texCoord) * vertexColor;
        if (gl_FragColor.a<0.5) {
           discard;
        }
}

Any help would be welcome! ^.^

Cheers,
Abiram
Title: Re: EGL_BAD_ALLOC error
Post by: EgonOlsen on March 23, 2015, 07:00:10 pm
Hard to tell. It can't be the shader itself, because i don't see anything in there that can fail on any current device. Is this the complete log output? Nothing is printed out before this?
Title: Re: EGL_BAD_ALLOC error
Post by: AeroShark333 on March 25, 2015, 02:15:08 pm
Yes this is the complete log output
Title: Re: EGL_BAD_ALLOC error
Post by: EgonOlsen on March 25, 2015, 04:56:08 pm
How do you load the shader?
Title: Re: EGL_BAD_ALLOC error
Post by: AeroShark333 on March 27, 2015, 11:43:44 am
GLSLShader loader:
Code: [Select]
GLSLShader shader = new GLSLShader(getStringFromFile(R.raw.alphatest_vs),
getStringFromFile(R.raw.alphatest_fs));

//apply to all objects
iH = new InnerHead(shader);
oH = new OuterHead(shader);

Textfile loader:
Code: [Select]
private String getStringFromFile(int id) {
final InputStream stream = getResources().openRawResource(id);
final BufferedReader reader = new BufferedReader(new InputStreamReader(
stream));
String result = "";
try {
String line;
while ((line=reader.readLine()) != null) {
result += line + "\n";
}
} catch (final IOException e) {
e.printStackTrace();
}
return result;
}
Title: Re: EGL_BAD_ALLOC error
Post by: EgonOlsen on March 27, 2015, 12:24:48 pm
Try to replace your printStackTrace with throwing a new RuntimeException that wraps the IOException. Maybe the problem isn't the shader or the driver but the loading itself. With your code, this will remain more or less unnoticed. And don't forget to close the stream. Your current code doesn't do this. It's good practice IMHO to do this in a finally-block.
Title: Re: EGL_BAD_ALLOC error
Post by: AeroShark333 on April 05, 2015, 02:17:01 pm
Something like this?:
Code: [Select]
private String getStringFromFile(final int id) {
final InputStream stream1 = getResources().openRawResource(id);
final BufferedReader reader = new BufferedReader(
new InputStreamReader(stream1));
String result = "";
try {
String line;
while ((line = reader.readLine()) != null) {
result += line + "\n";
}
} catch (final IOException e1) {
final InputStream stream2 = getResources().openRawResource(id);
result = Loader
.loadTextFile(stream2);
try {
stream2.close();
} catch (IOException e2) {
// Doesn't matter
e2.printStackTrace();
}
if (result == "" || result == null) {
throw new RuntimeException(
"Could not get the String from the Resources");
} else {
return result;
}
} finally {
try {
stream1.close();
reader.close();
} catch (IOException e3) {
// Doesn't matter
e3.printStackTrace();
}
}
return result;
}

One problem is that this error does not show up a lot in the Google Play Store Developers Console really... Which makes it harder for me to judge whether the bug/crash is fixed or not.
Title: Re: EGL_BAD_ALLOC error
Post by: EgonOlsen on April 07, 2015, 01:11:11 pm
No, not quite like that. It's better to use the RuntimeException constructor that takes the source exception as an additional parameter. The way you have it now only tells you that it didn't work out but hides the actual cause.
Title: Re: EGL_BAD_ALLOC error
Post by: AeroShark333 on April 07, 2015, 07:01:46 pm
So basically:
Code: [Select]
throw new RuntimeException(
"Could not get the String from the Resources", e1);
Title: Re: EGL_BAD_ALLOC error
Post by: EgonOlsen on April 08, 2015, 12:03:41 pm
Yes, something like that.
Title: Re: EGL_BAD_ALLOC error
Post by: AeroShark333 on April 14, 2015, 02:45:48 pm
So I got a new stacktrace...

Code: [Select]
java.lang.RuntimeException: [ 1428953336458 ] - ERROR: java.lang.RuntimeException: [ 1428953336457 ] - ERROR: java.lang.RuntimeException: [ 1428953336456 ] - ERROR: java.lang.RuntimeException: [ 1428953336450 ] - ERROR: Failed to load and compile fragment shaders!
at com.threed.jpct.Logger.log(Logger.java:206)
at com.threed.jpct.GLSLShader.loadProgram(GLSLShader.java:1077)
at com.threed.jpct.GLSLShader.<init>(GLSLShader.java:265)
at com.threed.jpct.GL20.<init>(GL20.java:124)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1440)
at com.threed.jpct.GLRenderer.init(GLRenderer.java:403)
at com.threed.jpct.GLRenderer.init(GLRenderer.java:384)
at com.threed.jpct.FrameBuffer.<init>(FrameBuffer.java:94)
at com.threed.jpct.FrameBuffer.<init>(FrameBuffer.java:119)
at com.aeroshark333.skinviewer.SkinActivity$ViewerRenderer.onSurfaceChanged(SkinActivity.java:1484)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1401)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1154)

at com.threed.jpct.Logger.log(Logger.java:206)
at com.threed.jpct.Logger.log(Logger.java:150)
at com.threed.jpct.GLSLShader.<init>(GLSLShader.java:269)
at com.threed.jpct.GL20.<init>(GL20.java:124)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1440)
at com.threed.jpct.GLRenderer.init(GLRenderer.java:403)
at com.threed.jpct.GLRenderer.init(GLRenderer.java:384)
at com.threed.jpct.FrameBuffer.<init>(FrameBuffer.java:94)
at com.threed.jpct.FrameBuffer.<init>(FrameBuffer.java:119)
at com.aeroshark333.skinviewer.SkinActivity$ViewerRenderer.onSurfaceChanged(SkinActivity.java:1484)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1401)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1154)

at com.threed.jpct.Logger.log(Logger.java:206)
at com.threed.jpct.Logger.log(Logger.java:138)
at com.threed.jpct.GLRenderer.init(GLRenderer.java:405)
at com.threed.jpct.GLRenderer.init(GLRenderer.java:384)
at com.threed.jpct.FrameBuffer.<init>(FrameBuffer.java:94)
at com.threed.jpct.FrameBuffer.<init>(FrameBuffer.java:119)
at com.aeroshark333.skinviewer.SkinActivity$ViewerRenderer.onSurfaceChanged(SkinActivity.java:1484)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1401)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1154)

at com.threed.jpct.Logger.log(Logger.java:206)
at com.threed.jpct.Logger.log(Logger.java:150)
at com.threed.jpct.FrameBuffer.<init>(FrameBuffer.java:96)
at com.threed.jpct.FrameBuffer.<init>(FrameBuffer.java:119)
at com.aeroshark333.skinviewer.SkinActivity$ViewerRenderer.onSurfaceChanged(SkinActivity.java:1484)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1401)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1154)

Code:
Code: [Select]
public ViewerRenderer(final boolean use3dSword,
final boolean use2dSword, final boolean supportsEs2,
final TextureManager tM) {
                        // irrelevant code
GLSLShader shader = new GLSLShader(
getStringFromFile(R.raw.alphatest_vs),
getStringFromFile(R.raw.alphatest_fs));
                       // irrelevant code
}
Code: [Select]
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
// irrelevant code
     this.frameBuffer = new FrameBuffer(width, height); //line 1484
                       // irrelevant code
}
Code: [Select]
private String getStringFromFile(final int id) {
final InputStream stream1 = getResources().openRawResource(id);
final BufferedReader reader = new BufferedReader(
new InputStreamReader(stream1));
String result = "";
try {
String line;
while ((line = reader.readLine()) != null) {
result += line + "\n";
}
} catch (final IOException e1) {
final InputStream stream2 = getResources().openRawResource(id);
result = Loader.loadTextFile(stream2);
try {
stream2.close();
} catch (IOException e2) {
// Doesn't matter
e2.printStackTrace();
}
if (result == "" || result == null) {
throw new RuntimeException(
"Could not get the String from the Resources", e1);
} else {
return result;
}
} finally {
try {
stream1.close();
reader.close();
} catch (IOException e3) {
// Doesn't matter
e3.printStackTrace();
}
}
return result;
}

EDIT:
Some side information:
- Crash happened on a Android 2.3.3 - 2.3.7 (Device 'name': h712a)
- The version of Skin Viewer 3D he used, does have the new shader loader.
- This stacktrace is new, I have not seen this one before... However, it sort of looks the same as the previous stacktrace... But somewhy FrameBuffer is involved this time? o.O
- Only one user (of the 82165 users (where 13948 active)) reported the crash with this stacktrace. The previous one was reported 9 times. (different users too)
Title: Re: EGL_BAD_ALLOC error
Post by: EgonOlsen on April 14, 2015, 07:07:52 pm
A complete log output isn't available? I would guess that this is either a driver issue (I was unable to find an Android device named "h712a"...only an older Envision monitor) or some problem with the gl context being destroyed or becoming invalid right after it's creation for some reason. Without a full log output, this is very hard to tell...
Title: Re: EGL_BAD_ALLOC error
Post by: AeroShark333 on April 15, 2015, 11:07:37 pm
No sorry, this is all I got...
Title: Re: EGL_BAD_ALLOC error
Post by: EgonOlsen on April 17, 2015, 02:03:59 pm
...than it's pretty hard to find the problem without the device that has it. There exist several frameworks that allow for better, more detailed feedback in case of an error. Maybe that's an option... ???