出错日志:
01-08 15:32:44.677 10317 10317 F DEBUG : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
01-08 15:32:44.677 10317 10317 F DEBUG : Build fingerprint: 'PAX/unknown/unknown:10/QP1A.191105.004/eng.linmj.20210105.152410:userdebug/release-keys'
01-08 15:32:44.677 10317 10317 F DEBUG : Revision: '0'
01-08 15:32:44.677 10317 10317 F DEBUG : ABI: 'arm'
01-08 15:32:44.679 10317 10317 F DEBUG : Timestamp: 2021-01-08 15:32:44+0800
01-08 15:32:44.679 10317 10317 F DEBUG : pid: 3373, tid: 10308, name: Thread-111 >>> com.paxsz.irface.raysees <<<
01-08 15:32:44.679 10317 10317 F DEBUG : uid: 1000
01-08 15:32:44.679 10317 10317 F DEBUG : signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
01-08 15:32:44.679 10317 10317 F DEBUG : Abort message: 'JNI DETECTED ERROR IN APPLICATION: obj == null
01-08 15:32:44.679 10317 10317 F DEBUG : in call to CallVoidMethodV'
01-08 15:32:44.679 10317 10317 F DEBUG : r0 00000000 r1 00002844 r2 00000006 r3 b916ef50
01-08 15:32:44.680 10317 10317 F DEBUG : r4 b916ef64 r5 b916ef48 r6 00000d2d r7 0000016b
01-08 15:32:44.680 10317 10317 F DEBUG : r8 b916ef60 r9 b916ef50 r10 b916ef80 r11 b916ef70
01-08 15:32:44.680 10317 10317 F DEBUG : ip 00002844 sp b916ef20 lr eddbdcb7 pc eddbdcca
01-08 15:32:44.688 10317 10317 F DEBUG :
01-08 15:32:44.688 10317 10317 F DEBUG : backtrace:
01-08 15:32:44.688 10317 10317 F DEBUG : #00 pc 0005ecca /apex/com.android.runtime/lib/bionic/libc.so (abort+166) (BuildId: 382e04da0c4d6d7d06edbd53601a5dd4)
01-08 15:32:44.689 10317 10317 F DEBUG : #01 pc 00382d71 /apex/com.android.runtime/lib/libart.so (art::Runtime::Abort(char const*)+1600) (BuildId: e321af3eb104ac43f13e5744596284b2)
01-08 15:32:44.692 10317 10317 F DEBUG : #02 pc 0000857d /system/lib/libbase.so (android::base::LogMessage::~LogMessage()+412) (BuildId: 7a6528cfcb4efe233fdbfb73b5095897)
01-08 15:32:44.692 10317 10317 F DEBUG : #03 pc 0028e2d9 /apex/com.android.runtime/lib/libart.so (art::JavaVMExt::JniAbort(char const*, char const*)+1228) (BuildId: e321af3eb104ac43f13e5744596284b2)
01-08 15:32:44.692 10317 10317 F DEBUG : #04 pc 00011498 /data/app/com.paxsz.irface.raysees-vS3h2wW51ABPBuA9QmcUjQ==/lib/arm/libUVCCamera.so (_JNIEnv::CallVoidMethod(_jobject*, _jmethodID*, ...)+52) (BuildId: 8592169407668b052fad9bf72e38d511e33494c4)
01-08 15:32:44.692 10317 10317 F DEBUG : #05 pc 000113b4 /data/app/com.paxsz.irface.raysees-vS3h2wW51ABPBuA9QmcUjQ==/lib/arm/libUVCCamera.so (UVCPreview::do_capture_callback(_JNIEnv*, uvc_frame*)+244) (BuildId: 8592169407668b052fad9bf72e38d511e33494c4)
01-08 15:32:44.693 10317 10317 F DEBUG : #06 pc 00011064 /data/app/com.paxsz.irface.raysees-vS3h2wW51ABPBuA9QmcUjQ==/lib/arm/libUVCCamera.so (UVCPreview::do_capture(_JNIEnv*)+144) (BuildId: 8592169407668b052fad9bf72e38d511e33494c4)
01-08 15:32:44.693 10317 10317 F DEBUG : #07 pc 00010aac /data/app/com.paxsz.irface.raysees-vS3h2wW51ABPBuA9QmcUjQ==/lib/arm/libUVCCamera.so (UVCPreview::capture_thread_func(void*)+64) (BuildId: 8592169407668b052fad9bf72e38d511e33494c4)
01-08 15:32:44.693 10317 10317 F DEBUG : #08 pc 000a6177 /apex/com.android.runtime/lib/bionic/libc.so (__pthread_start(void*)+20) (BuildId: 382e04da0c4d6d7d06edbd53601a5dd4)
01-08 15:32:44.693 10317 10317 F DEBUG : #09 pc 000601b1 /apex/com.android.runtime/lib/bionic/libc.so (__start_thread+30) (BuildId: 382e04da0c4d6d7d06edbd53601a5dd4)
01-08 15:32:44.768 1867 4667 I chatty : uid=1041(audioserver) writer identical 7 lines
01-08 15:32:44.788 1867 4667 V audio_platform: mode(0),devices(0x2):platform device:OUT_DULSPK(0x4)
01-08 15:32:44.800 3373 4830 D DepthCalc: GetDepthByteData time: 426 [ 784.827042] selinux: avc: denied { set } for property=persist.system.usbperm.disable pid=2237 uid=1000 gid=1000 scontext=u:r:system_server:s0 tcontext=u:object_r:default_prop:s0 tclass=property_service permissive=0
[ 784.827042]
结合代码:
void UVCPreview::do_capture_callback(JNIEnv *env, uvc_frame_t *frame) {
ENTER();
if (LIKELY(frame)) {
uvc_frame_t *callback_frame = frame;
if (mFrameCallbackObj) {
if (mFrameCallbackFunc) {
callback_frame = get_frame(callbackPixelBytes);
if (LIKELY(callback_frame)) {
int b = mFrameCallbackFunc(frame, callback_frame);
recycle_frame(frame);
if (UNLIKELY(b)) {
LOGW("failed to convert for callback frame");
goto SKIP;
}
} else {
LOGW("failed to allocate for callback frame");
callback_frame = frame;
goto SKIP;
}
}
jobject buf = env->NewDirectByteBuffer(callback_frame->data, callbackPixelBytes);
//if(mFrameCallbackObj){
env->CallVoidMethod(mFrameCallbackObj, iframecallback_fields.onFrame, buf);
//}
env->ExceptionClear();
env->DeleteLocalRef(buf);
}
SKIP:
recycle_frame(callback_frame);
}
EXIT();
}原因:
多线程的问题,在调用
env->CallVoidMethod(mFrameCallbackObj, iframecallback_fields.onFrame, buf);mFrameCallbackObj已经被销毁了。正确的是应该加同步锁。我这里没有加,而是再一次判断非空。测试基本上不会在报错了。严格意义上还是要加同步锁,理论上我这样修改还是会低概率导致null报错。