问题
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:
A/libc: invalid address or address of corrupt block 0xabc932a8 passed to dlfree A/libc: Fatal signal 11 (SIGSEGV), code 2, fault addr 0xdeadbaad in tid 28493 (RxNewThreadSche) A/DEBUG: pid: 28376, tid: 28493, name: RxNewThreadSche >>> com.package.name <<<
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();
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.
EDIT
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();
}
EDIT 2
Current threads in getFaceDetector method:
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
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!
回答1:
The error is not caused by RxJava. It is caused by native code, probably by the library libmobile_vision_face.so.
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: 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() {
...
来源:https://stackoverflow.com/questions/46077045/fatal-signal-11-sigsegv-when-use-rxjava-and-play-services-vision