Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to catch "Fatal signal 11 (SIGSEGV)"?

In my android OpenGL ES project i recently had an error in my shader code, which apparently caused a "Fatal signal 11 (SIGSEGV)" in the OpenGL Thread here:

GLES32.glCompileShader(glShaderHandle);

I resolved the error and it works fine again but I had a hard time finding out where that error came from. Of course I try to "catch" shader errors like this:

GLES32.glGetShaderiv(glShaderHandle, GLES32.GL_COMPILE_STATUS, result, 0);

But in the case of the SIGSEGV error, the java code didn't even get to that point. Also trying to catch the error with try/catch didn't work. The app crashes anyway. I guess the error happens in native c code.

Is there a way to handle errors like this from java code to keep the app from crashing?

like image 956
theCNG27 Avatar asked Mar 04 '23 05:03

theCNG27


1 Answers

You can't catch it. This is a segfault. Its a crash in C. It doesn't turn into a Java stack trace, its treated as a hard fault by linux and the app is immediately terminated.

You may be able to write a C signal handler and do some processing, but I really wouldn't recommend it. And you would not be able to continue the app in any way from this point, as the application is now in undefined behavior.

If you do want to attempt that (I really don't suggest it) read How to write a signal handler to catch SIGSEGV? for an overview of the issues.

like image 138
Gabe Sechan Avatar answered Mar 15 '23 02:03

Gabe Sechan