简体   繁体   English

JNI - SIGSEGV 信号 SIGSEGV:在工作线程中时地址无效

[英]JNI - SIGSEGV signal SIGSEGV: invalid address when in worker thread

I have a JNI call from android, where I send data (bytes, width and height) for image processing.我有一个来自 android 的 JNI 调用,我在其中发送数据(字节、宽度和高度)以进行图像处理。 The function works fine when executing from the main android thread.从主 android 线程执行时,function 工作正常。 I want to call from another thread, to avoiding blocking UI, but when I do that the JNI throws a memory error.我想从另一个线程调用,以避免阻塞 UI,但是当我这样做时,JNI 会抛出 memory 错误。 If I call from main thread, works fine.如果我从主线程调用,工作正常。

The error is thrown from env->GetIntArrayRegion(...) .该错误是从env->GetIntArrayRegion(...)引发的。

extern "C"
JNIEXPORT jobjectArray JNICALL
Java_topcodes_TopCodesScanner_searchTopCodesNative(JNIEnv *env, jobject thiz, jint image_width,
                                                   jint image_height, jintArray image_data) {
    auto image_data_size = env->GetArrayLength(image_data);
    jint image_data_buf[image_data_size];
    // error in this line
    env->GetIntArrayRegion(image_data, 0, image_data_size, image_data_buf);

The way I'm creating the new threads is this:我创建新线程的方式是这样的:

private val executorService by lazy { Executors.newFixedThreadPool(4) }

    override fun analyze(image: ImageProxy) {
        
        executorService.submit {  // if comment, works fine
            try {
                val blocks = findBlocks(image)
                handler.post { listener(blocks); }
            } finally {
                image.close()
            }
        }                         // if comment, works fine
    }

Here is the stack trace.这是堆栈跟踪。

memcpy 0x0000007f8f938d9c
art::JNI::*GetIntArrayRegion(_JNIEnv, _jintArray*, int, int, int*) 0x0000007f8bddcea0
art::CheckJNI::GetPrimitiveArrayRegion(char const*, art::Primitive::Type, _JNIEnv*, _jarray*, int, int, void*) 0x0000007f8bbf07fc
<unknown> 0x0000007f750c0aec
<unknown> 0x0000007f750c0708
topcodes.TopCode[] topcodes.TopCodesScanner.searchTopCodesNative(int, int, int[]) 0x0000007f7844218c
art_quick_invoke_stub 0x0000007f8bbb6ca8
art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*) 0x0000007f8bbc5b80
artInterpreterToCompiledCodeBridge 0x0000007f8bf64574
bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*) 0x0000007f8bd3fc48
art::JValue art::interpreter::ExecuteGotoImpl<false, false>(art::Thread*, art::DexFile::CodeItem const*, art::ShadowFrame&, art::JValue) 0x0000007f8bb76e44
art::interpreter::EnterInterpreterFromEntryPoint(art::Thread*, art::DexFile::CodeItem const*, art::ShadowFrame*) 0x0000007f8bd1d9c4
artQuickToInterpreterBridge 0x0000007f8bfd4944
art_quick_to_interpreter_bridge 0x0000007f8bbc0a28
<unknown> 0x0000007f8bbc0b90

I've searched for similar questions.我已经搜索过类似的问题。 Thanks in advance.提前致谢。

auto image_data_size = env->GetArrayLength(image_data);
jint image_data_buf[image_data_size];

Don't make a C-style array if you don't know the size at compile time.如果您在编译时不知道大小,请不要创建 C 样式的数组。
See: Why does C++ allow variable length arrays that aren't dynamically allocated?请参阅: 为什么 C++ 允许非动态分配的可变长度 arrays?

Use std::vector<jint> image_data_buf(image_data_size) instead.请改用std::vector<jint> image_data_buf(image_data_size)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android NDK引发信号SIGSEGV:通过JNI在Activity中获得GoogleSignInClient后,地址无效 - Android NDK throwning signal SIGSEGV: invalid address after getting GoogleSignInClient in Activity via JNI 线程中SetDoubleArrayRegion上的JNI SIGSEGV - JNI SIGSEGV on SetDoubleArrayRegion in Thread Android:捕捉 SIGSEGV 信号 JNI - Android : Catch SIGSEGV signal JNI Android NDK 抛出信号 sigsegv:调试模式下的无效地址 - Android NDK throwing signal sigsegv: invalid address in debug mode 没有故障地址的 Android 信号 11 (SIGSEGV) - Android signal 11 (SIGSEGV) with no fault address 我在运行JNI android app A / libc时收到错误消息:致命信号11(SIGSEGV)在0xdeadd00d(代码= 1),线程17729 - I receive error message when run JNI android app A/libc﹕ Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1), thread 17729 错误:将Mat对象从Java传递到jni函数时,出现“致命信号11(SIGSEGV),代码1” - Error: “Fatal signal 11 (SIGSEGV), code 1” when passing Mat object from java to jni function Android从线程错误中调用jni方法(A / libc:致命信号11(SIGSEGV),代码1,TID 13620中的故障加法器0xdeadbaad(AsyncTask#3)) - Android calling jni method from thread Error(A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0xdeadbaad in tid 13620 (AsyncTask #3)) Android JNI:CallObjectMethod上的SIGSEGV - Android JNI: SIGSEGV on CallObjectMethod Android Signal 11(SIGSEGV) - Android Signal 11 (SIGSEGV)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM