问题描述
在我的应用程序中,我使用图片中人物位置的定义.之后,我使用RxJava处理生成的图像并输出结果.完成后,重新运行该过程.都可以在三星,华为,魅族和其他设备(Android 5.0及更高版本)上完美运行.但是在小米上(无论什么版本的android),我都会收到此错误:
In my application I use the definition of the person position in the picture. After that, using RxJava I process the resulting image and output the result. After complete re-run that process. All working perfectly on devices such as samsung, huawei, meizu and other (with android version 5.0 and higher). But on xiaomi (no matter what version of android) I getting this error:
有时它会在启动过程后崩溃,有时会工作5到6次.但这总是迫使我完成申请.我不能将所有代码都放在这里,但是我认为这是由于:
Sometimes it crashes after start procces, sometimes it working 5-6 times. But it always force finishing my application.I can't put here all my code but I think this is due to:
FaceDetector.release();
因为当我不使用此行时,我的应用程序崩溃了,否则就崩溃了,只是不工作FaceDetector(在我使用过的其他设备上).
because when I don't use this line my app crashed if not, just not working FaceDetector (on other devices i used it).
崩溃后,小米生成了此错误.
After crash xiaomi generated this error.
编辑
private static FaceDetector sFaceDetector;
private static FaceDetectorUtil sFaceDetectorUtil;
private static WeakReference<Context> mContext;
public static void init(Context context) {
if (sFaceDetectorUtil == null) {
sFaceDetectorUtil = new FaceDetectorUtil(context);
}
}
private FaceDetectorUtil(Context context) {
mContext = new WeakReference<>(context);
}
public static FaceDetector getDetector() {
if (sFaceDetector != null) {
sFaceDetector.release();
}
return sFaceDetector = new FaceDetector.Builder(mContext.get())
.setTrackingEnabled(false)
.setLandmarkType(FaceDetector.ALL_LANDMARKS)
.setMode(FaceDetector.FAST_MODE)
.build();
}
编辑2
getFaceDetector方法中的当前线程:
Current threads in getFaceDetector method:
华为P9精简版:
数:13
线程:HeapTaskDaemon
线程:FinalizerDaemon
线程:RxComputationThreadPool-2
线程:pool-1-thread-1
线程:GoogleApiHandler
线程:RxComputationThreadPool-1
线程:JavaCPP分配器
线程:ReferenceQueueDaemon
线程:FinalizerWatchdogDaemon
线程:RxCachedWorkerPoolEvictor-1
线程:RxComputationThreadPool-3
线程:RxNewThreadScheduler-17
线程:pool-2-thread-1
Huawei P9 lite:
Count: 13
Threads: HeapTaskDaemon
Threads: FinalizerDaemon
Threads: RxComputationThreadPool-2
Threads: pool-1-thread-1
Threads: GoogleApiHandler
Threads: RxComputationThreadPool-1
Threads: JavaCPP Deallocator
Threads: ReferenceQueueDaemon
Threads: FinalizerWatchdogDaemon
Threads: RxCachedWorkerPoolEvictor-1
Threads: RxComputationThreadPool-3
Threads: RxNewThreadScheduler-17
Threads: pool-2-thread-1
小米Redmi 4x :
数:22
线程:信号捕捉器
线程:RxComputationThreadPool-2
线程:活页夹:5858_3
线程:活页夹:5858_2
线程:hwuiTask1
线程:RxComputationThreadPool-1
线程:JDWP
线程:FinalizerWatchdogDaemon
线程:RenderThread
线程:RxCachedWorkerPoolEvictor-1
线程:RxComputationThreadPool-3
线程:ReferenceQueueDaemon
线程:活页夹:5858_1
线程:pool-1-thread-1
线程:JavaCPP分配器
线程:HeapTaskDaemon
线程:主
线程:GoogleApiHandler
线程:FinalizerDaemon
线程:RxNewThreadScheduler-4
线程:hwuiTask2
线程:pool-2-thread-1
Xiaomi Redmi 4x:
Count: 22
Threads: Signal Catcher
Threads: RxComputationThreadPool-2
Threads: Binder:5858_3
Threads: Binder:5858_2
Threads: hwuiTask1
Threads: RxComputationThreadPool-1
Threads: JDWP
Threads: FinalizerWatchdogDaemon
Threads: RenderThread
Threads: RxCachedWorkerPoolEvictor-1
Threads: RxComputationThreadPool-3
Threads: ReferenceQueueDaemon
Threads: Binder:5858_1
Threads: pool-1-thread-1
Threads: JavaCPP Deallocator
Threads: HeapTaskDaemon
Threads: main
Threads: GoogleApiHandler
Threads: FinalizerDaemon
Threads: RxNewThreadScheduler-4
Threads: hwuiTask2
Threads: pool-2-thread-1
如果有人可以帮助我,我将不胜感激.问候!
I would really appreciate if someone can help to me. Regards!
推荐答案
该错误不是由RxJava引起的.它是由本机代码引起的,可能由库libmobile_vision_face.so引起.
The error is not caused by RxJava. It is caused by native code, probably by the library libmobile_vision_face.so.
如果您无法更改本机代码,则可以通过避免调用FaceDetector.release()
并仅对其进行一次初始化(例如在您的Application
类中)来解决该错误.
If you can't change the native code you can workaround the error by avoid calling FaceDetector.release()
and initialising it only once (in your Application
class for example).
UPD:对于单例方法,我想到要按以下方式使用它:
UPD: for the singleton approach I had in mind to use it as follows:
public static FaceDetector getDetector() {
if (sFaceDetector != null) {
return sFaceDetector;
} else {
return sFaceDetector = new FaceDetector.Builder(mContext.get())
.setTrackingEnabled(false)
.setLandmarkType(FaceDetector.ALL_LANDMARKS)
.setMode(FaceDetector.FAST_MODE)
.build();
}
}
如果您尝试并行调用同步(可能导致错误),您也可以先尝试将同步添加到您的方法中:
Also you could just try to add the synchronisation to your method first, in case if you try to call it in parallel (what could lead to the error):
public static synchronized FaceDetector getDetector() {
...
这篇关于使用RxJava和播放服务愿景时出现致命信号11(SIGSEGV)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!