google-ar / arcore-android-sdk

ARCore SDK for Android Studio
https://developers.google.com/ar
Other
4.98k stars 1.22k forks source link

crash when calling ArCamera_getPose #1359

Closed brianm-sra closed 2 years ago

brianm-sra commented 2 years ago

SPECIFIC ISSUE ENCOUNTERED

A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x1d89a04f1aecd0 in tid 19279 (GLThread 54), pid 19212 (app namespace mentioned) E/native: E0224 11:30:38.129759 19404 jni_helper.cc:109] Attempt to get JNIEnv on thread not attached to JVM W/native: W0224 11:30:38.129943 19404 scoped_global_ref.cc:29] Unable to delete global reference, JNIEnv missing

VERSIONS USED

STEPS TO REPRODUCE THE ISSUE

I took code from hello_ar_c and modified it, porting some Java code from raw_depth_java to C/C++ In one of the files that I added, raw_depth_data.cpp, I have a RawDepthData::create(const ArSession session, const ArFrame frame) method that includes this code as a part of it:

    ArCamera* camera;
    ArFrame_acquireCamera(session, frame, &camera);
    LOGD("in RawDepthData::create, acquired camera");
    ArCameraIntrinsics** cameraIntrinsics;
    ArCameraIntrinsics_create(session, cameraIntrinsics);
    ArCamera_getTextureIntrinsics(session, camera, *cameraIntrinsics);
    LOGD("in RawDepthData::create, got camera intrinsics");
    ArPose** cameraPose;
    ArPose_create(session, nullptr, cameraPose);
    LOGD("in RawDepthData::create, allocated memory for cameraPose");
    ArCamera_getPose(session, camera, *cameraPose);
    LOGD("in RawDepthData::create, got cameraPose");

It successfully gets past the steps up to and including ArPose_create

When the ArCamera_getPose method is called, my app crashes

logcat shows

I/hello_ar_example_c: entering HelloArApplication::OnDrawFrame
D/hello_ar_example_c: in onDrawFrame, acquired camera
D/hello_ar_example_c: entering RawDepthData::create
D/hello_ar_example_c: in RawDepthData::create, acquired raw depth image
D/hello_ar_example_c: in RawDepthData::create, acquired raw depth confidence image
D/hello_ar_example_c: in RawDepthData::create, acquired camera
D/hello_ar_example_c: in RawDepthData::create, got camera intrinsics
D/hello_ar_example_c: in RawDepthData::create, allocated memory for cameraPose
A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x1d9cc04f1aecd0 in tid 21559 (GLThread 54), pid 21500
E/native: E0224 11:43:27.826726   21700 jni_helper.cc:109] Attempt to get JNIEnv* on thread not attached to JVM
W/native: W0224 11:43:27.827217   21700 scoped_global_ref.cc:29] Unable to delete global reference, JNIEnv* missing

and then repeats those last two lines about jni_helper.cc:109 and scoped_global_ref.cc:29 multiple times in the logcat

brianm-sra commented 2 years ago

I tried renaming the file from .cpp to .cc (to be consistent with other files in the project), and changing nullptr to NULL (the documentation says if NULL is passed in, then it will initialize the output to identity matrix), but there was no change. Still seeing the same crash and error in logcat,

brianm-sra commented 2 years ago

I fixed that particular crash by changing code to

ArPose* cameraPose = nullptr; ArPose_create(session, nullptr, &cameraPose); ArCamera_getPose(session, camera, cameraPose);

but now I just get the crash slightly later at a different point Sigh Continuing to debug remaining code