Rust Get JNIEnv error: JNI ОБНАРУЖЕНА ОШИБКА В ПРИЛОЖЕНИИ: использование недопустимого задания
03-14 21:43:32.166 30174-30192/com.example.arcore_example A/zygote: java_vm_ext.cc:504] JNI DETECTED ERROR IN APPLICATION: use of invalid jobject 0xd35ff7a0
03-14 21:43:32.166 30174-30192/com.example.arcore_example A/zygote: java_vm_ext.cc:504] "Thread-2" prio=10 tid=12 Runnable
03-14 21:43:32.166 30174-30192/com.example.arcore_example A/zygote: java_vm_ext.cc:504] | group="main" sCount=0 dsCount=0 flags=0 obj=0x13a00000 self=0xe4ffbe00
03-14 21:43:32.166 30174-30192/com.example.arcore_example A/zygote: java_vm_ext.cc:504] | sysTid=30192 nice=-10 cgrp=default sched=0/0 handle=0xd3405970
03-14 21:43:32.166 30174-30192/com.example.arcore_example A/zygote: java_vm_ext.cc:504] | state=R schedstat=( 811197 20677 3 ) utm=0 stm=0 core=3 HZ=100
03-14 21:43:32.166 30174-30192/com.example.arcore_example A/zygote: java_vm_ext.cc:504] | stack=0xd330b000-0xd330d000 stackSize=1006KB
03-14 21:43:32.166 30174-30192/com.example.arcore_example A/zygote: java_vm_ext.cc:504] | held mutexes= "mutator lock"(shared held)
03-14 21:43:32.166 30174-30192/com.example.arcore_example A/zygote: java_vm_ext.cc:504] native: #00 pc 002c45b7 /system/lib/libart.so (_ZN3art15DumpNativeStackERNSt3__113basic_ostreamIcNS0_11char_traitsIcEEEEiP12BacktraceMapPKcPNS_9ArtMethodEPv+130)
03-14 21:43:32.166 30174-30192/com.example.arcore_example A/zygote: java_vm_ext.cc:504] native: #01 pc 00355a83 /system/lib/libart.so (_ZNK3art6Thread9DumpStackERNSt3__113basic_ostreamIcNS1_11char_traitsIcEEEEbP12BacktraceMapb+202)
03-14 21:43:32.166 30174-30192/com.example.arcore_example A/zygote: java_vm_ext.cc:504] native: #02 pc 00351f67 /system/lib/libart.so (_ZNK3art6Thread4DumpERNSt3__113basic_ostreamIcNS1_11char_traitsIcEEEEbP12BacktraceMapb+34)
03-14 21:43:32.166 30174-30192/com.example.arcore_example A/zygote: java_vm_ext.cc:504] native: #03 pc 0022f6e9 /system/lib/libart.so (_ZN3art9JavaVMExt8JniAbortEPKcS2_+736)
03-14 21:43:32.166 30174-30192/com.example.arcore_example A/zygote: java_vm_ext.cc:504] native: #04 pc 0022fb53 /system/lib/libart.so (_ZN3art9JavaVMExt9JniAbortFEPKcS2_z+66)
03-14 21:43:32.166 30174-30192/com.example.arcore_example A/zygote: java_vm_ext.cc:504] native: #05 pc 003599c9 /system/lib/libart.so (_ZNK3art6Thread13DecodeJObjectEP8_jobject+352)
03-14 21:43:32.166 30174-30192/com.example.arcore_example A/zygote: java_vm_ext.cc:504] native: #06 pc 000d1ab1 /system/lib/libart.so (_ZN3art11ScopedCheck13CheckInstanceERNS_18ScopedObjectAccessENS0_12InstanceKindEP8_jobjectb+64)
Когда я пытаюсь построить приложение, основанное на arcore через rust, но некоторые функции arcore должны нуждаться в переменной env из jni, такой как 'ArSession_create'
pub fn ArSession_create(env: *mut ::std::os::raw::c_void,
application_context: *mut ::std::os::raw::c_void,
out_session_pointer: *mut *mut ArSession)
-> ArStatus;
Но когда я запустил приложение, произошла ошибка, я понятия не имею, как его отладить. Я думаю, один или несколько указателей получат неправильное значение.
Ниже мой код ржавчины:
extern crate android_injected_glue;
mod ffi_arcore {
include!(concat!(env!("OUT_DIR"), "/arcore_bindings.rs"));
}
use ffi_arcore::{ArCamera, ArConfig, ArFrame, ArSession, ArStatus};
use ffi_arcore::{ArCamera_getProjectionMatrix, ArFrame_acquireCamera, ArFrame_create, ArSession_create, ArConfig_create};
use android_injected_glue::Event;
use android_injected_glue::{add_sender, get_app, write_log};
use android_injected_glue::ffi::{android_app, ANativeActivity, JavaVM, JNIEnv, JNIInvokeInterface};
fn main() {
use std::sync::mpsc::channel;
write_log("main() has been called");
let (sender, receiver) = channel::<Event>();
add_sender(sender);
let app: &mut android_app = get_app();
let activity: *const ANativeActivity = (*app).activity;
let vm: *mut JavaVM = unsafe { (*activity).vm };
let jniInvokeInterface: *const JNIInvokeInterface = unsafe { (*vm).functions };
// pub AttachCurrentThread: extern fn(*mut JavaVM, *mut *mut JNIEnv, *mut c_void) -> jint,
let mut c_void_ptr: *mut std::os::raw::c_void = ::std::ptr::null_mut();
let mut env: *mut JNIEnv = unsafe { (*activity).env };
let attach = unsafe { (*jniInvokeInterface).AttachCurrentThread };
attach(vm, &mut env, c_void_ptr);
let ctx: *mut ::std::os::raw::c_void = unsafe { (*app).userData as *mut ::std::os::raw::c_void };
let mut out_session_pointer: *mut ArSession = ::std::ptr::null_mut();
let mut ar_status: ArStatus = unsafe { ArSession_create(env as *mut ::std::os::raw::c_void, ctx, &mut out_session_pointer) };
loop {
write_log(&format!("_______EVENT_________{:?}", receiver.recv()));
}
}