Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR) error on android virtual device
-
I am able to run my android qt app on a real android 11 (general mobile G510) mobile phone
BUT
I cannot run same app in a android virtual device. It throws "F libc : Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x2787c in tid 2755 (qtMainLoopThrea), pid 2722 (org.gp_touch)" error. Then application dies.rarely, i get same error on real device but generally it works.
this is the Application output:
I org.gp_touch: Late-enabling -Xcheck:jni I org.gp_touch: Unquickening 12 vdex files! W org.gp_touch: Unexpected CPU variant for X86 using defaults: x86 I ndk_translation: Initialized NDK translation (armv7l), version 0.2.2 D ApplicationLoaders: Returning zygote-cached class loader: /system/framework/android.test.base.jar D NetworkSecurityConfig: No Network Security Config specified, using platform default D NetworkSecurityConfig: No Network Security Config specified, using platform default W System : ClassLoader referenced unknown path: D Qt JAVA : Class org.qtproject.qt5.android.bluetooth.QtBluetoothBroadcastReceiver does not implement setActivity method I QtCore : Start I Qt : qt started I Gralloc4: mapper 4.x is not supported D HostConnection: createUnique: call D HostConnection: HostConnection::get() New Host Connection established 0xf23d1ce0, tid 2722 D goldfish-address-space: allocate: Ask for block of size 0x100 D goldfish-address-space: allocate: ioctl allocate returned offset 0x3f7ffe000 size 0x2000 D HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_sync_buffer_data ANDROID_EMU_read_color_buffer_dma GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_2 D libEGL : loaded /vendor/lib/egl/libEGL_emulation.so D libEGL : loaded /vendor/lib/egl/libGLESv1_CM_emulation.so D libEGL : loaded /vendor/lib/egl/libGLESv2_emulation.so D HostConnection: HostConnection::get() New Host Connection established 0xf23d3560, tid 2755 D HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_sync_buffer_data ANDROID_EMU_read_color_buffer_dma GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_2 W libGalvanoPlot_Touch_armeabi-v7a.so: d10 W libGalvanoPlot_Touch_armeabi-v7a.so: d11 W libGalvanoPlot_Touch_armeabi-v7a.so: libpng warning: iCCP: known incorrect sRGB profile F libc : Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x2787c in tid 2755 (qtMainLoopThrea), pid 2722 (org.gp_touch) 12:36:12: "org.gp_touch" died.
in the output, i can see these lines are related but i don't know what that means.
- D HostConnection: HostConnection::get() New Host Connection established 0xf23d1ce0, tid 2722
- D HostConnection: HostConnection::get() New Host Connection established 0xf23d3560, tid 2755
- F libc : Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x2787c in tid 2755 (qtMainLoopThrea), pid 2722 (org.gp_touch)
When i run in debug mode, i get "Fatal signal 11 (SIGSEGV), code 2 (SEGV_ACCERR)" error instead of "code 1 (SEGV_MAPERR)". And there is no backtrace output because app couldn't started properly.
My AVD :
My Qt kit:
used packages in project that included in .pro file :
QT += core charts quick androidextras svg bluetooth widgets
and i'm using Java native interface in my app to use phone usb. but i think app dies before that codes are executed.thanks for any help.
-
I solved the problem!
In short:
There was a pointer with random value i found. I thought it would be nullptr without assigning nullptr but it wasn't. The program was calling it sometimes before setting of the normal value of pointer. then error comes. i handled the pointer as how it should and i got rid of the errorThe story:
In the code there is a QPROPERTY that contains my experiments in classA.h
Q_PROPERTY(QQmlListProperty<experiment> sorted_exps READ get_sorted_exps_prlist NOTIFY sorted_expsChanged)
in get_sorted_exps_prlist function, i call a function via my thePointerB to collect some experiment objects as QVector
thePointerB is a pointer of classB. the classB contains some QML QObject pointers. So, when Gui completed, i call a function from QML in classA to create an ClassB object. -My classB object takes QML object pointers as constructor parameters.- After i create the classB object, i assign it to my thePointerB.So, if android device complete the gui before the cpp part, program runs normally. If gui is later, program crashes due to calling a not setted pointer. OR, sometimes the pointer is null sometimes not on first the allocation time. I don't know it is possible.
But it was a little bit more complicated. when i trace the code with qWarnings, i can see the function of classB that i call via thePointerB is running normally at the beginning. but when program reached the lines that use private variables of classB, android program crashes. That was probably because of there is no constructed object. By the way, i confused because of this difference between function-variable's behaviour.
Anyway, i already had an if() to check nullptr. (i was aware the pointer not setted yet. But i didn't know it wasn't null). Right now, it is like this:
get_sorted_exps_prlist (){ if(thePointerB != nullptr){ //classA.cpp . . }}
and i assigned nullptr the pointer. it was like classB *thePointerB; before. Now:
classB *thePointerB = nullptr; // classB.h
and problem disappeared.
HOW I FOUND THE BUG
you need to get backtrace the program on crush. i couldn't get it via QT debugger. i got it via my colleague's android phone(xiaomi mix 2s) after 2-3 crushes, the phone pop-up a warning to report crashes. and there was a button that you can see an little error report. the report was containing Fatal signal 11 (SIGSEGV) error as well as the backtrace. In the backtrace, the function of classB that i called via theProinterB was there. i wasn't know this feature. after that, i found the bug.https://developer.android.com/games/optimize/crash the page contains an error like i got. please control + f for "signal 11 (SIGSEGV), code 1 (SEGV_MAPERR)"
to get backtrace on ANY ANDROID PHONE, Just go to developer options and select debugging app via "Select debug app". Then click to "Bug report" and select Full report. After 10 -20 second later (probably depends on bug count) you will get the reprot file from notifications. then open the bugreport-blabla.txt and search backtrace. you willl find your native error cause.
-
I solved the problem!
In short:
There was a pointer with random value i found. I thought it would be nullptr without assigning nullptr but it wasn't. The program was calling it sometimes before setting of the normal value of pointer. then error comes. i handled the pointer as how it should and i got rid of the errorThe story:
In the code there is a QPROPERTY that contains my experiments in classA.h
Q_PROPERTY(QQmlListProperty<experiment> sorted_exps READ get_sorted_exps_prlist NOTIFY sorted_expsChanged)
in get_sorted_exps_prlist function, i call a function via my thePointerB to collect some experiment objects as QVector
thePointerB is a pointer of classB. the classB contains some QML QObject pointers. So, when Gui completed, i call a function from QML in classA to create an ClassB object. -My classB object takes QML object pointers as constructor parameters.- After i create the classB object, i assign it to my thePointerB.So, if android device complete the gui before the cpp part, program runs normally. If gui is later, program crashes due to calling a not setted pointer. OR, sometimes the pointer is null sometimes not on first the allocation time. I don't know it is possible.
But it was a little bit more complicated. when i trace the code with qWarnings, i can see the function of classB that i call via thePointerB is running normally at the beginning. but when program reached the lines that use private variables of classB, android program crashes. That was probably because of there is no constructed object. By the way, i confused because of this difference between function-variable's behaviour.
Anyway, i already had an if() to check nullptr. (i was aware the pointer not setted yet. But i didn't know it wasn't null). Right now, it is like this:
get_sorted_exps_prlist (){ if(thePointerB != nullptr){ //classA.cpp . . }}
and i assigned nullptr the pointer. it was like classB *thePointerB; before. Now:
classB *thePointerB = nullptr; // classB.h
and problem disappeared.
HOW I FOUND THE BUG
you need to get backtrace the program on crush. i couldn't get it via QT debugger. i got it via my colleague's android phone(xiaomi mix 2s) after 2-3 crushes, the phone pop-up a warning to report crashes. and there was a button that you can see an little error report. the report was containing Fatal signal 11 (SIGSEGV) error as well as the backtrace. In the backtrace, the function of classB that i called via theProinterB was there. i wasn't know this feature. after that, i found the bug.https://developer.android.com/games/optimize/crash the page contains an error like i got. please control + f for "signal 11 (SIGSEGV), code 1 (SEGV_MAPERR)"
to get backtrace on ANY ANDROID PHONE, Just go to developer options and select debugging app via "Select debug app". Then click to "Bug report" and select Full report. After 10 -20 second later (probably depends on bug count) you will get the reprot file from notifications. then open the bugreport-blabla.txt and search backtrace. you willl find your native error cause.
-
If you still not able to work on virtual device but okey on real device
Get backtrace via virtual device extended controls (if you don't know how to do, just google it)
seek for the error kinda like:
04-14 12:36:11.004 10121 2780 2780 F DEBUG : backtrace: 04-14 12:36:11.004 10121 2780 2780 F DEBUG : #00 pc 000d0780 /system/lib/libndk_translation.so (ndk_translation::ExecuteGuest(ndk_translation::ProcessState*)+288) (BuildId: ca20d07948eb897d9ee91bdeb9bd0155) 04-14 12:36:11.004 10121 2780 2780 F DEBUG : #01 pc 000d09ba /system/lib/libndk_translation.so (ndk_translation::(anonymous namespace)::RunGuestCall(unsigned int, int, int, unsigned int*)+266) (BuildId: ca20d07948eb897d9ee91bdeb9bd0155) 04-14 12:36:11.004 10121 2780 2780 F DEBUG : #02 pc 000d0b1a /system/lib/libndk_translation.so (ndk_translation::RunGuestCall(unsigned int, ndk_translation::GuestArgumentBuffer*)+42) (BuildId: ca20d07948eb897d9ee91bdeb9bd0155) 04-14 12:36:11.004 10121 2780 2780 F DEBUG : #03 pc 000d3a2a /system/lib/libndk_translation.so (ndk_translation::(anonymous namespace)::RunGuestJNIFunction(unsigned int, ndk_translation::GuestArgumentBuffer*)+74) (BuildId: ca20d07948eb897d9ee91bdeb9bd0155) 04-14 12:36:11.004 10121 2780 2780 F DEBUG : #04 pc 00096357 <anonymous:c3a0c000>
if you have this error, your apk does not contain the suitable ABI. Like you built it just for armeabi-v7 and your virtual device gives error while translating the code. The solution is very simple. Go to Qt Creator Project settings and check the all ABIs like my screenshot.