如何解决mediapipe.components.ExternalTextureConverter.setSurfaceTextureAndAttachToGLContext 返回 null使应用程序崩溃 onResume
我正在处理 jiuqiant's mediapipe face detection app。 我克隆了 repo,应用程序运行良好,检测到我的脸,但是当我暂停应用程序并恢复时,它崩溃了。 这一行有错误 permalink
converter.setSurfaceTextureAndAttachToGLContext(
previewFrameTexture,displaySize.getWidth(),displaySize.getHeight());
用这个日志
D/CameraXPreviewHelper: viewSize or frameSize is null.
E/SurfaceView: Exception configuring surface
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.util.Size.getWidth()' on a null object reference
at com.example.myfacedetectionapp.MainActivity$1.surfaceChanged(MainActivity.java:146)
at android.view.SurfaceView.updateSurface(SurfaceView.java:802)
at android.view.SurfaceView$2.onPreDraw(SurfaceView.java:163)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:977)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3044)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1845)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8235)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:994)
at android.view.Choreographer.doCallbacks(Choreographer.java:806)
at android.view.Choreographer.doFrame(Choreographer.java:738)
at android.view.Choreographer$FramedisplayEventReceiver.run(Choreographer.java:980)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:226)
at android.app.ActivityThread.main(ActivityThread.java:7178)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:503)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:942)
很明显 setSurfaceTextureAndAttachToGLContext 正在返回空值。
查看源代码(下面是 setSurfaceTextureAndAttachToGLContext
中的 com.google.mediapipe.components.ExternalTextureConverter
函数)
if (viewSize != null && this.frameSize != null) {
Size optimalSize = this.getoptimalViewSize(viewSize);
return optimalSize != null ? optimalSize : this.frameSize;
} else {
Log.d("CameraXPreviewHelper","viewSize or frameSize is null.");
return null;
}
似乎 this.frameSize 为空。但我不知道如何解决这个问题。
我也尝试对值进行硬编码
converter.setSurfaceTextureAndAttachToGLContext(previewFrameTexture,200,200);
但它也会出错
I/GLConsumer: [SurfaceTexture-0-13076-0] attachToContext
E/GLConsumer: [SurfaceTexture-0-13076-0] attachToContext: GLConsumer is already attached to a context
E/BpSurfaceComposerClient: Failed to transact (-1)
E/BpSurfaceComposerClient: Failed to transact (-1)
D/GlThread: Stopping GL thread ExternalTextureConverter
D/CaptureSession: opening capture session.
E/AndroidRuntime: FATAL EXCEPTION: ExternalTextureConverter
Process: com.example.myfacedetectionapp,PID: 13076
java.lang.RuntimeException: Error during attachToGLContext (see logcat for details)
at android.graphics.SurfaceTexture.attachToGLContext(SurfaceTexture.java:289)
at com.google.mediapipe.components.ExternalTextureConverter$renderThread.setSurfaceTextureAndAttachToGLContext(ExternalTextureConverter.java:247)
at com.google.mediapipe.components.ExternalTextureConverter.lambda$setSurfaceTextureAndAttachToGLContext$2$ExternalTextureConverter(ExternalTextureConverter.java:166)
at com.google.mediapipe.components.-$$Lambda$ExternalTextureConverter$VQm8xcL00VolxXr4rMIgGUKVKnw.run(UnkNown Source:8)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:226)
at com.google.mediapipe.glutil.GlThread.run(GlThread.java:141)
是不是版本问题。看不懂。
重新创建的步骤 -
解决方法
可以使用给定 here 的类工作。 只需将 com directory 放在您的 app/src/main 中。
请记住从 libs 目录中的 .aar 文件中删除重复的类。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。