gpt4 book ai didi

android - JNI-SIGSEGV信号SIGSEGV : invalid address when in worker thread

转载 作者:行者123 更新时间:2023-12-03 13:06:12 24 4
gpt4 key购买 nike

我有一个来自Android的JNI调用,我在其中发送数据(字节,宽度和高度)以进行图像处理。从主android线程执行时,该函数工作正常。我想从另一个线程进行调用,以避免阻塞UI,但是当我这样做时,JNI会引发内存错误。如果我从主线程调用,效果很好。
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);
我创建新线程的方式是这样的:
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
}
这是堆栈跟踪。
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
我搜索了类似的问题。提前致谢。

最佳答案

auto image_data_size = env->GetArrayLength(image_data);
jint image_data_buf[image_data_size];
如果您在编译时不知道大小,则不要制作C样式的数组。
另请: Why does C++ allow variable length arrays that aren't dynamically allocated?
请改用 std::vector<jint> image_data_buf(image_data_size)

关于android - JNI-SIGSEGV信号SIGSEGV : invalid address when in worker thread,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66498433/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com