-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
Description
System information (version)
- OpenCV => 4.6.0
- Operating System / Platform => Android 7.1.1 (Sony Xperia Z5 Compact)
- Compiler => Android Studio 2021.2.1 Patch 2 on Windows 11
Detailed description
Calling OpenCVLoader.initDebug() once at the beginning of an application succeeds, but a SIGSEGV will subsequently be raised in libart.so everytime a screen rotation occurs. The SIGSEGV will be raised in between onPause and onResume calls for the fragment.
Steps to reproduce
-
Open Android Studio 2021.2.1 Patch 2
-
File > New > New Project... > Phone and Tablet > select 'Basic Activity'. Make sure the language is set to Java.
-
Download OpenCV 4.6.0 (latest release) from sourceforget.net and unzip the 'sdk' directory next to the settings.gradle file (also next to the 'app' folder of the application) as a folder named 'opencv' (not 'sdk')
-
File > New > Import Module... > source directory : the 'opencv' directory mentionned above
-
Give a name to the opencv module, for instance 'opencv', and finish the import procedure. We now have two projects in the IDE, :app and :opencv
-
Open settings.gradle and reverse the order of these two lines (for some reason, they are in the wrong order when the project is imported):
project(':opencv').projectDir = new File(rootDir, 'opencv/') include 'opencv' -
get rid of the kotlin extension declaration, as the project is written in Java
-
Build the project and launch a debug session on a Sony Xperia Z5 Compact (E5823) device with Android 7.1.1 Nougat. The application is launched successfully
-
The first fragment shows up, now rotate the screen, everything is fine.
-
Exit the application
-
Override FirstFragment's onCreate method by adding this code:
@Override public void onCreate(Bundle b) { super.onCreate(b); boolean success = OpenCVLoader.initDebug(); } -
Following this edit, the IDE complains OpenCVLoader is not a recognized class - follow the suggestions to import the '........._main' module and then do 'Import class'. Now the class is recognized and everything compiles fine.
-
Launch a new debug session
-
'success' will be true, above, as can be seen with the debugger if need be
-
Now rotate the device's screen
-
A SIGSEGV occurs after onPause() has been called., and the debugger is entered
SIGSEGV (signal SIGSEGV: invalid address (fault address: 0x0)) libart.so: art_sigsegv_fault<unknown> 0x0000007f92a99904 art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*) 0x0000007fb0cba304 art::interpreter::ArtInterpreterToCompiledCodeBridge(art::Thread*, art::ArtMethod*, art::DexFile::CodeItem const*, art::ShadowFrame*, art::JValue*) 0x0000007fb0e6a5b0 bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*) 0x0000007fb0e6358c bool art::interpreter::DoInvoke<(art::InvokeType)2, false, false>(art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*) 0x0000007fb0e92fdc art::JValue art::interpreter::ExecuteSwitchImpl<false, false>(art::Thread*, art::DexFile::CodeItem const*, art::ShadowFrame&, art::JValue, bool) 0x0000007fb0e86cb4 art::interpreter::Execute(art::Thread*, art::DexFile::CodeItem const*, art::ShadowFrame&, art::JValue, bool) 0x0000007fb0e3c950 art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::DexFile::CodeItem const*, art::ShadowFrame*, art::JValue*) 0x0000007fb0e42648 bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*) 0x0000007fb0e63570 bool art::interpreter::DoInvokeVirtualQuick<false>(art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*) 0x0000007fb0e80b74 art::JValue art::interpreter::ExecuteSwitchImpl<false, false>(art::Thread*, art::DexFile::CodeItem const*, art::ShadowFrame&, art::JValue, bool) 0x0000007fb0e87938 ... [lots of lines] ... art::InvokeWithVarArgs(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jmethodID*, std::__va_list) 0x0000007fb1004d14 art::JNI::CallStaticVoidMethodV(_JNIEnv*, _jclass*, _jmethodID*, std::__va_list) 0x0000007fb0f20b00 <unknown> 0x0000007fb3305278 android::AndroidRuntime::start(char const*, android::Vector<android::String8> const&, bool) 0x0000007fb3307890 <unknown> 0x0000005570287264 __libc_init 0x0000007fb2bbf89c -
Carrying execution with the Continue button works fine (surprisingly ?)
-
onResume() is called and execution resumes normally.
Any subsequent screen rotation will result in a SIGSEGV.
This is very annoying when debugging on the device, which I always prefer.
At the beginning, I thought it was a problem with my code, so I posted a message on stackoverflow:
SIGSEGV libart.so exception only occuring on one computer when debugging, not on the other
Because I managed to build a simple repro, I am posting this issue here.
Surprisingly, there is one computer on which I don't experience the problem, but it is an older Android Studio version (2021.2.1 with no patch).
Issue submission checklist
- I report the issue, it's not a question
- I checked the problem with documentation, FAQ, open issues,
forum.opencv.org, Stack Overflow, etc and have not found any solution - I updated to the latest OpenCV version and the issue is still there
- There is reproducer code and related data files: videos, images, onnx, etc