Skip to content

Commit 398487b

Browse files
committed
fix crash issue on imitate app
1 parent 74eed0f commit 398487b

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

subs/cpp_native/src/main/cpp/cpp_native.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,9 @@ Java_com_example_cpp_1native_internal_NativeHouse_doHeavyWorkAsync(JNIEnv *env,
8282
// 3. 子线程 attach
8383
if (gVm->AttachCurrentThread(&env, nullptr) != 0) return;
8484
worker(env, gCallback); // 真正干活
85-
// 4. 别忘了 detach,否则线程退出会崩
86-
gVm->DetachCurrentThread();
87-
// 5. 全局引用用完要释放
85+
// 4. 全局引用用完要释放(必须在 detach 之前使用有效的 env)
8886
env->DeleteGlobalRef(gCallback);
87+
// 5. 别忘了 detach,否则线程退出会崩
88+
gVm->DetachCurrentThread();
8989
}).detach();
9090
}
91-

0 commit comments

Comments
 (0)