Fatal signal 11 (SIGSEGV) on start up - HELP!

Dear forum,

I’m desperate! I’m cracking my head on this SIGSEGV all day and can’t find the source!

It’s been a long time since I tested my android app, since I was on the apothecary branch, doing the iOS side. I now switched to latest master, and I’m crashing on startup and I can’t pin point the issue.

The crash happens on:

static {
    	try{
    		Log.i("OF","static init");
    		System.loadLibrary("neondetection"); 
	    	if(hasNeon()){
	    		Log.i("OF","loading neon optimized library");
	    		System.loadLibrary("OFAndroidApp_neon");
	    	}else{
	    		Log.i("OF","loading not-neon optimized library");
	    		System.loadLibrary("OFAndroidApp");
	    	}
    	}catch(Throwable e){
    		Log.i("OF","failed neon detection, loading not-neon library",e);
    		System.loadLibrary("OFAndroidApp"); // <<=====THIS LINE
    	}
    	Log.i("OF","initializing app");
    }

So I tested the examples and they do work, so it’s not an enviromental issue. So I started stripping down more and more code until I was left with almost nothing - and it fixed it. So I started putting back cpp files to be compiled, and the problem returns, but it seems that I have to do a clean and rebuild each time in order to see if the problem currently exists or not, other wise it may not refresh it properly. Now I don’t actually run more code, I just add more classes that are unreachable. It seems that something that I compile causes this, but I have no clue on how to know what is actually wrong!

The logcat says:

Fatal signal 11 (SIGSEGV) at 0xfffffffc (code=1), thread 9216

Right after it tried to load that neon lib, fails, goes to the catch and tries to load the not-neon one.

I’ll reiterate: it’s not an environmental issue. When I remove most of my cpp files and stay with a skeleton, the same problem does load, it’s just when I add my other classes it fails.

Any push in the right direction will be greatly appreciated!!

Thanks!

Tal

1 Like

are you using a videograbber? in that case the problem might be related to: https://github.com/openframeworks/openFrameworks/issues/3752

No @arturo, I’m not. Any other ideas?

In the meanwhile, by doing allot of tedious work, I pinpointed the problem to some of the members of a static struct variable I have in one of the files… It’s frustrating to resort to trial and error. Sounds like a serious ndk bug to me.

yes static variables are usually cause of undetermined crashes. you can use this pattern:

static MyClass & object(){
    static MyClass * object = new MyClass();
    return *object;
}

which usually solves any initialization or destruction problems.

also you can debug native code compiling in debug mode and using ndk-gdb

Wow, thanks @arturo, that’s seems to do the trick! I really don’t understand why this is happening. What’s wrong with having a static member? He’s not exposed in the h, and it’s not even used at all - just declared!

I’m a little scared that I’ll run into similar problems in other files besides the one I already tracked down. Can you think of a good way for me to hunt these issues aside from carefully implement your pattern on every static member?

I never tried debugging the native side. Can you point me to some resources for this? Besides, since I’m crashing on initialization, and not actual code I’m running, will debugging even help me in this case?

Thanks again,

Tal

For future readers: that was definitely the problem. I’ll now know not to assume that all other static members are initialized when I’m initializing a static member. Seems so obvious now that I know this. Here’s a good explanation on the problem and the solution as suggested by @arturo. Read everything related to “static initialization order fiasco”: https://isocpp.org/wiki/faq/ctors#static-init-order

yeah that’s it. there’s even one more problem, the static deinitialization fiasco which happens when a destructor of a static variable depends on another, since you can’t control the destruction order it can crash and it’s not even deterministic. that’s why you initialize it in the heap using new and never destroy them

Not sure I understand that one. If my member is static, it will never be out of scope, and thus will never be destroyed, or am I missing something?

1 Like

Same thing happening here, and luckily found this post with more info.Getting a fatal error on boot on a phone, anothers run fine same apk.

Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 25203

This same app works without problems on a broken asus android phone. A newer redmi phone, same apk, crashes on boot with fatal 11 error above. When writing a new post in the forum luckily found this post with lots of nice explanations and options to tackle the issue.

Things that caught my eyes through logcat debug log, with ** (the same arm7 apk works on other phones…)

06-19 05:10:56.435 25175-25175/? W/main: type=1400 audit(0.0:7518): avc: granted { read } for name="u:object_r:net_dns_prop:s0" dev="tmpfs" ino=12508 scontext=u:r:untrusted_app_25:s0:c512,c768 tcontext=u:object_r:net_dns_prop:s0 tclass=file
06-19 05:10:56.450 25175-25175/? I/.s373.kalyx012: Late-enabling -Xcheck:jni
** 06-19 05:10:56.499 25175-25175/? E/.s373.kalyx012: Unknown bits set in runtime_flags: 0x28000
06-19 05:10:56.910 25175-25175/net.s373.kalyx012a I/Perf: Connecting to perf service.

...

06-19 05:10:57.101 25175-25175/net.s373.kalyx012a I/OF: initializing app
06-19 05:10:57.103 25175-25175/net.s373.kalyx012a I/OF: OFAndroid init...
06-19 05:10:57.104 25175-25175/net.s373.kalyx012a D/OF: glCreate
06-19 05:10:57.104 25175-25175/net.s373.kalyx012a V/OF: trying to find class: net.s373.kalyx012a.R$layout
06-19 05:10:57.105 25175-25201/net.s373.kalyx012a I/OFAndroidLifeCycleHelper: starting resources extractor
06-19 05:10:57.120 25175-25175/net.s373.kalyx012a D/ForceDarkHelper: updateByCheckExcludeList: pkg: net.s373.kalyx012a activity: cc.openframeworks.kalyx012a.OFActivity@1d3f3a8
06-19 05:10:57.136 25175-25175/net.s373.kalyx012a D/ForceDarkHelper: updateByCheckExcludeList: pkg: net.s373.kalyx012a activity: cc.openframeworks.kalyx012a.OFActivity@1d3f3a8
06-19 05:10:57.251 25175-25197/net.s373.kalyx012a E/Perf: Fail to get file list net.s373.kalyx012a
** 06-19 05:10:57.252 25175-25197/net.s373.kalyx012a E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
    Fail to get file list oat
    getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
06-19 05:10:57.335 25175-25175/net.s373.kalyx012a W/.s373.kalyx012: Long monitor contention with owner Thread-3 (25201) at java.lang.String[] android.content.res.AssetManager.nativeList(long, java.lang.String)(AssetManager.java:-2) waiters=0 in boolean android.content.res.AssetManager.isUpToDate() for 197ms
06-19 05:10:57.339 25175-25201/net.s373.kalyx012a I/OFAndroidLifeCycleHelper: sd mounted: true
06-19 05:10:57.342 25175-25201/net.s373.kalyx012a I/OFAndroidLifeCycleHelper: creating app directory: /storage/emulated/0/Android/data/net.s373.kalyx012a/files
06-19 05:10:57.346 25175-25201/net.s373.kalyx012a I/OF: Using storage location: /storage/emulated/0
06-19 05:10:57.353 25175-25201/net.s373.kalyx012a I/ofAppAndroidWindow: setting app dir name to: "/storage/emulated/0/Android/data/net.s373.kalyx012a/files"
06-19 05:10:57.356 25175-25175/net.s373.kalyx012a D/ForceDarkHelper: updateByCheckExcludeList: pkg: net.s373.kalyx012a activity: cc.openframeworks.kalyx012a.OFActivity@1d3f3a8
06-19 05:10:57.360 25175-25175/net.s373.kalyx012a I/chatty: uid=10284(net.s373.kalyx012a) identical 1 line
06-19 05:10:57.362 25175-25175/net.s373.kalyx012a D/ForceDarkHelper: updateByCheckExcludeList: pkg: net.s373.kalyx012a activity: cc.openframeworks.kalyx012a.OFActivity@1d3f3a8
06-19 05:10:57.369 25175-25175/net.s373.kalyx012a D/OF: glResume
    f��Z@B.
    readbrightness,out2:992.
06-19 05:10:57.394 25175-25175/net.s373.kalyx012a W/Looper: Slow Looper main: Activity net.s373.kalyx012a/cc.openframeworks.kalyx012a.OFActivity is 522ms late (wall=1ms running=0ms ClientTransaction{ callbacks=[android.app.servertransaction.TopResumedActivityChangeItem] }) because of 2 msg, msg 1 took 120ms (seq=2 late=2ms h=android.app.ActivityThread$H w=110), msg 2 took 425ms (seq=3 late=98ms h=android.app.ActivityThread$H w=159)
06-19 05:10:57.395 25175-25175/net.s373.kalyx012a D/OF: Create surface
06-19 05:10:57.396 25175-25175/net.s373.kalyx012a D/ForceDarkHelper: updateByCheckExcludeList: pkg: net.s373.kalyx012a activity: cc.openframeworks.kalyx012a.OFActivity@1d3f3a8
06-19 05:10:57.399 25175-25175/net.s373.kalyx012a D/OF: glResume
    addView surface
06-19 05:10:57.402 25175-25201/net.s373.kalyx012a I/OFAndroidLifeCycleHelper: onResume
06-19 05:10:57.419 25175-25198/net.s373.kalyx012a I/AdrenoGLES: QUALCOMM build                   : c692a3f, Ie3bb699d95
    Build Date                       : 09/29/20
    OpenGL ES Shader Compiler Version: EV031.27.05.02
    Local Branch                     : 
    Remote Branch                    : refs/tags/AU_LINUX_ANDROID_LA.UM.8.6.2.R1.10.00.00.537.053
    Remote Branch                    : NONE
    Reconstruct Branch               : NOTHING
    Build Config                     : S L 8.0.10 AArch32
06-19 05:10:57.424 25175-25198/net.s373.kalyx012a I/AdrenoGLES: PFP: 0x005ff112, ME: 0x005ff066
06-19 05:10:57.450 25175-25198/net.s373.kalyx012a W/Gralloc3: mapper 3.x is not supported
06-19 05:10:57.490 25175-25203/net.s373.kalyx012a I/OF: onSurfaceCreated
06-19 05:10:57.932 25175-25203/net.s373.kalyx012a W/BpBinder: Slow Binder: BpBinder transact took 438ms, interface=android.app.IActivityTaskManager, code=41 oneway=false
06-19 05:10:57.974 25175-25175/net.s373.kalyx012a W/BpBinder: Slow Binder: BpBinder transact took 472ms, interface=com.android.internal.view.IInputMethodManager, code=8 oneway=false
06-19 05:10:57.994 25175-25175/net.s373.kalyx012a W/Looper: Slow Looper main: doFrame is 478ms late because of 1 msg, msg 1 took 491ms (seq=16 late=86ms h=android.view.ViewRootImpl$ViewRootHandler w=6)
** 06-19 05:10:58.012 25175-25203/net.s373.kalyx012a A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 25203 (GLThread 1620), pid 25175 (.s373.kalyx012a)

yes, so my code uses a couple of static variables, would have never though this could be an issue, thank you for sharing this info, will see if changing static works