Scanner icon indicating copy to clipboard operation
Scanner copied to clipboard

onResume onPause 切换时so内部报错,app无法捕获导致闪退。

Open devzwy opened this issue 2 years ago • 2 comments

感谢作者提供的扫描库,我在使用时发现频繁的操作前后台切换,调用Scanner库的onPauseonResume时会发生so层的异常,app层无法捕获导致直接闪退,非必现。可能复现的流程如下:

  • 进入页面,开始扫描(正常)
  • 切换到后台,扫描暂停(正常)
  • 切换到前台继续扫描(非必现so层崩溃)

setScanner拦截器中实现了另外的一层逻辑,因为咱们这个库好像不支持新能源车牌的识别(不知道是否是我配置异常,我的需求是要能同时识别两种,识别到哪一种就处理哪种,好像库里可以指定识别的车牌长度,但是指定了好像只能识别某一种。),期待回复。

部分代码

  • xml
 <com.shouzhong.scanner.ScannerView
            android:id="@+id/sv"
            android:layout_width="match_parent"
            android:layout_height="205dp"
            android:background="@color/black" />
  • code
    override fun initView(savedInstanceState: Bundle?) {
        mViewBind.vm = mViewModel
        mViewBind.click = ProxyClick()
        initBar()
        initScan()
        initListener()
    }

private fun initScan() {
        // 车牌识别算法配置参数
        val parameter = HyperLPRParameter()
            .setDetLevel(HyperLPR3.DETECT_LEVEL_LOW)
            .setMaxNum(1)
            .setRecConfidenceThreshold(0.85f)

        // 初始化(仅执行一次生效)
        HyperLPR3.getInstance().init(this, parameter);

        mViewBind.activityLpv.setInputListener(onInputListener)

        mViewBind.activityLpv.setKeyboardContainerLayout(mViewBind.mainRlContainer)
        mViewBind.activityLpv.showLastView()
//        mViewBind.activityLpv.hideLastView()
        mViewBind.activityLpv.onSetTextColor(R.color.colorAccent)

        mViewBind.sv.setViewFinder(ViewFinder(this))
        mViewBind.sv.setEnableLicensePlate(true)
        mViewBind.sv.restartPreviewAfterDelay(1)
        val nv21 = NV21(this)
        mViewBind.sv.setScanner { data, width, height ->
            val plates = HyperLPR3.getInstance().plateRecognition(nv21.nv21ToBitmap(data, width, height), TypeDefine.CAMERA_ROTATION_0, HyperLPR3.STREAM_BGRA)
            if (plates.isNotEmpty()) {
                return@setScanner Result().also {
                    it.data = plates[0].code
                    it.type = Result.TYPE_LICENSE_PLATE
                }
            } else {
                return@setScanner null
            }
        }
        //mViewBind.sv.onResume()
        mViewBind.sv.setCallback {
            if (it.data.isNotEmpty()) {
                mViewBind.activityLpv.setDefaultStr(it.data)
                mViewModel.carNo.value = it.data
//                mViewModel.getCardInfo(it.data)
            }
            mViewBind.sv.restartPreviewAfterDelay(200)
        }
    }
    override fun onPause() {
        super.onPause()
        mViewBind.sv.onPause()
//        mViewModel.showScanView.value = false
    }


    override fun onResume() {
        super.onResume()
        initBar()
        mViewBind.sv.onResume()
//        mViewModel.showScanView.value = true
    }

错误日志

2023-09-05 16:26:38.635 27784-27784 CameraBase              cn.uexpo                             E  [getNumberOfCameras] scan getNumberOfCameras reading number of cameras count: 2
2023-09-05 16:26:39.298 27784-27987 HyperLPR3-Native        cn.uexpo                             D  cost: 0.160804
2023-09-05 16:26:39.738 27784-27800 Camera                  cn.uexpo                             I  Camera >>>>>>>>> release
2023-09-05 16:26:39.742 27784-27800 ScanCameraSwitchUtils   cn.uexpo                             I  open scan Camera_Scan end release 1
2023-09-05 16:26:39.844 27784-27987 HyperLPR3-Native        cn.uexpo                             D  cost: 0.160254
2023-09-05 16:26:39.888 27784-27784 JetpackMvvm             cn.uexpo                             D  onActivityPaused : ui.activity.MainActivity
2023-09-05 16:26:39.889 27784-27784 CrashReport             cn.uexpo                             D  >>> cn.uexpo.ui.activity.MainActivity onPaused <<<
2023-09-05 16:26:39.891 27784-27784 CrashReport-Native      cn.uexpo                             I  Set native info: isAppForeground(false)
2023-09-05 16:26:40.065 27784-27784 Camera                  cn.uexpo                             I  Camera >>>>>>>>> release
2023-09-05 16:26:40.065 27784-27784 ScanCameraSwitchUtils   cn.uexpo                             I  closeCameraAndOpenScanner Exception scan Service:android.os.IScanService$Stub$Proxy@89b5833,State:false
2023-09-05 16:26:40.251 27784-27784 JetpackMvvm             cn.uexpo                             D  onActivityStopped : ui.activity.MainActivity
2023-09-05 16:26:40.254 27784-27784 LeakCanary              cn.uexpo                             D  Ignoring request to check for retained objects (app became invisible), already scheduled in 1937ms
2023-09-05 16:26:40.261 27784-27784 PhoneWindow             cn.uexpo                             V  DecorView setVisiblity: visibility = 4, Parent = android.view.ViewRootImpl@37ce4e2, this = DecorView@c7bddd7[MainActivity]
2023-09-05 16:26:40.701 27784-27816 LeakCanary              cn.uexpo                             D  Setting up flushing for Thread[InsetsAnimations,5,main]
2023-09-05 16:26:41.044 27784-27784 JetpackMvvm             cn.uexpo                             D  onActivityStarted : ui.activity.MainActivity
2023-09-05 16:26:41.046 27784-27784 AndroidAutoSize         cn.uexpo                             D  cn.uexpo.ui.activity.MainActivity used the global configuration.
2023-09-05 16:26:41.049 27784-27784 AndroidAutoSize         cn.uexpo                             D  The cn.uexpo.ui.activity.MainActivity has been adapted! 
                                                                                                    MainActivity Info: isBaseOnWidth = true, designWidthInDp = 375.000000, designWidthInSubunits = 375.000000, targetDensity = 1.920000, targetScaledDensity = 1.920000, targetDensityDpi = 307, targetXdpi
                                                                                                    = 1.920000, targetScreenWidthDp = 375, targetScreenHeightDp = 641
2023-09-05 16:26:41.053 27784-27784 PhoneWindow             cn.uexpo                             V  DecorView setVisiblity: visibility = 0, Parent = android.view.ViewRootImpl@37ce4e2, this = DecorView@c7bddd7[MainActivity]
2023-09-05 16:26:41.054 27784-27784 JetpackMvvm             cn.uexpo                             D  onActivityResumed : ui.activity.MainActivity
2023-09-05 16:26:41.055 27784-27784 CrashReport             cn.uexpo                             D  >>> cn.uexpo.ui.activity.MainActivity onResumed <<<
2023-09-05 16:26:41.057 27784-27784 CrashReport-Native      cn.uexpo                             I  Set native info: isAppForeground(true)
2023-09-05 16:26:41.068 27784-28101 Camera                  cn.uexpo                             I  Camera cameraInitVersion packageList:
2023-09-05 16:26:41.070 27784-27784 PhoneWindow             cn.uexpo                             V  DecorView setVisiblity: visibility = 0, Parent = android.view.ViewRootImpl@37ce4e2, this = DecorView@c7bddd7[MainActivity]
2023-09-05 16:26:41.221 27784-28101 ScanCameraSwitchUtils   cn.uexpo                             I  close scan Camera_Scan start cameraInitVersion ret:1
2023-09-05 16:26:41.336 27784-27784 CameraBase              cn.uexpo                             E  [getNumberOfCameras] scan getNumberOfCameras reading number of cameras count: 2
2023-09-05 16:26:41.386   511-511   Layer                   surfaceflinger                       E  [SurfaceView - cn.uexpo/cn.uexpo.ui.activity.MainActivity#0] No local sync point found
2023-09-05 16:26:42.005 27784-28101 HyperLPR3-Native        cn.uexpo                             D  cost: 0.159145
2023-09-05 16:26:42.192 27784-27815 LeakCanary              cn.uexpo                             D  Check for retained object found no objects remaining
2023-09-05 16:26:42.447 27784-27800 Camera                  cn.uexpo                             I  Camera >>>>>>>>> release
2023-09-05 16:26:42.452 27784-27800 ScanCameraSwitchUtils   cn.uexpo                             I  open scan Camera_Scan end release 1
2023-09-05 16:26:42.554 27784-28101 HyperLPR3-Native        cn.uexpo                             D  cost: 0.158630
2023-09-05 16:26:42.850 27784-28101 HyperLPR3-Native        cn.uexpo                             D  cost: 0.155176
2023-09-05 16:26:43.005 27784-27784 JetpackMvvm             cn.uexpo                             D  onActivityPaused : ui.activity.MainActivity
2023-09-05 16:26:43.006 27784-27784 CrashReport             cn.uexpo                             D  >>> cn.uexpo.ui.activity.MainActivity onPaused <<<
2023-09-05 16:26:43.008 27784-27784 CrashReport-Native      cn.uexpo                             I  Set native info: isAppForeground(false)
2023-09-05 16:26:43.155 27784-28101 HyperLPR3-Native        cn.uexpo                             D  cost: 0.158124
2023-09-05 16:26:43.227 27784-27784 Camera                  cn.uexpo                             I  Camera >>>>>>>>> release
2023-09-05 16:26:43.227 27784-27784 ScanCameraSwitchUtils   cn.uexpo                             I  closeCameraAndOpenScanner Exception scan Service:android.os.IScanService$Stub$Proxy@89b5833,State:false
2023-09-05 16:26:43.228 27784-28101 libc                    cn.uexpo                             A  Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 28101 (CameraHandlerTh), pid 27784 (cn.uexpo)
2023-09-05 16:26:43.411 28210-28210 DEBUG                   crash_dump64                         A  pid: 27784, tid: 28101, name: CameraHandlerTh  >>> cn.uexpo <<<
2023-09-05 16:26:43.418 27784-27784 JetpackMvvm             cn.uexpo                             D  onActivityStopped : ui.activity.MainActivity
2023-09-05 16:26:43.420 27784-27784 LeakCanary              cn.uexpo                             D  Scheduling check for retained objects in 5000ms because app became invisible
2023-09-05 16:26:43.427 27784-27784 PhoneWindow             cn.uexpo                             V  DecorView setVisiblity: visibility = 4, Parent = android.view.ViewRootImpl@37ce4e2, this = DecorView@c7bddd7[MainActivity]
2023-09-05 16:26:43.706 28210-28210 DEBUG                   crash_dump64                         A        #00 pc 00000000000ffa04  /data/app/~~rFL2u3WIWPjY7E1aJ8hlUA==/cn.uexpo-xB7DjqyolZEYB08lA1idEA==/lib/arm64/libLicensePlate.so (BuildId: 05857e9e5b0e8af297fdc74277cf733086bfa87e)
2023-09-05 16:26:43.706 28210-28210 DEBUG                   crash_dump64                         A        #01 pc 00000000001007b0  /data/app/~~rFL2u3WIWPjY7E1aJ8hlUA==/cn.uexpo-xB7DjqyolZEYB08lA1idEA==/lib/arm64/libLicensePlate.so (BuildId: 05857e9e5b0e8af297fdc74277cf733086bfa87e)
2023-09-05 16:26:43.706 28210-28210 DEBUG                   crash_dump64                         A        #02 pc 00000000003ab260  /data/app/~~rFL2u3WIWPjY7E1aJ8hlUA==/cn.uexpo-xB7DjqyolZEYB08lA1idEA==/lib/arm64/libLicensePlate.so (BuildId: 05857e9e5b0e8af297fdc74277cf733086bfa87e)
2023-09-05 16:26:43.706 28210-28210 DEBUG                   crash_dump64                         A        #03 pc 00000000003ab7ac  /data/app/~~rFL2u3WIWPjY7E1aJ8hlUA==/cn.uexpo-xB7DjqyolZEYB08lA1idEA==/lib/arm64/libLicensePlate.so (BuildId: 05857e9e5b0e8af297fdc74277cf733086bfa87e)
2023-09-05 16:26:43.706 28210-28210 DEBUG                   crash_dump64                         A        #04 pc 000000000067acb8  /data/app/~~rFL2u3WIWPjY7E1aJ8hlUA==/cn.uexpo-xB7DjqyolZEYB08lA1idEA==/lib/arm64/libLicensePlate.so
                                                                                                    (tbb::internal::custom_scheduler<tbb::internal::IntelSchedulerTraits>::local_wait_for_all(tbb::task&, tbb::task*)+848) (BuildId: 05857e9e5b0e8af297fdc74277cf733086bfa87e)
2023-09-05 16:26:43.706 28210-28210 DEBUG                   crash_dump64                         A        #05 pc 0000000000679978  /data/app/~~rFL2u3WIWPjY7E1aJ8hlUA==/cn.uexpo-xB7DjqyolZEYB08lA1idEA==/lib/arm64/libLicensePlate.so
                                                                                                    (tbb::internal::generic_scheduler::local_spawn_root_and_wait(tbb::task*, tbb::task*&)+180) (BuildId: 05857e9e5b0e8af297fdc74277cf733086bfa87e)
2023-09-05 16:26:43.706 28210-28210 DEBUG                   crash_dump64                         A        #06 pc 00000000003abae0  /data/app/~~rFL2u3WIWPjY7E1aJ8hlUA==/cn.uexpo-xB7DjqyolZEYB08lA1idEA==/lib/arm64/libLicensePlate.so (BuildId: 05857e9e5b0e8af297fdc74277cf733086bfa87e)
2023-09-05 16:26:43.706 28210-28210 DEBUG                   crash_dump64                         A        #07 pc 00000000003abb70  /data/app/~~rFL2u3WIWPjY7E1aJ8hlUA==/cn.uexpo-xB7DjqyolZEYB08lA1idEA==/lib/arm64/libLicensePlate.so (BuildId: 05857e9e5b0e8af297fdc74277cf733086bfa87e)
2023-09-05 16:26:43.706 28210-28210 DEBUG                   crash_dump64                         A        #08 pc 0000000000672248  /data/app/~~rFL2u3WIWPjY7E1aJ8hlUA==/cn.uexpo-xB7DjqyolZEYB08lA1idEA==/lib/arm64/libLicensePlate.so
                                                                                                    (tbb::interface7::internal::task_arena_base::internal_execute(tbb::interface7::internal::delegate_base&) const+420) (BuildId: 05857e9e5b0e8af297fdc74277cf733086bfa87e)
2023-09-05 16:26:43.706 28210-28210 DEBUG                   crash_dump64                         A        #09 pc 00000000003abdc8  /data/app/~~rFL2u3WIWPjY7E1aJ8hlUA==/cn.uexpo-xB7DjqyolZEYB08lA1idEA==/lib/arm64/libLicensePlate.so (cv::parallel_for_(cv::Range const&, cv::ParallelLoopBody
                                                                                                    const&, double)+552) (BuildId: 05857e9e5b0e8af297fdc74277cf733086bfa87e)
2023-09-05 16:26:43.706 28210-28210 DEBUG                   crash_dump64                         A        #10 pc 0000000000102f54  /data/app/~~rFL2u3WIWPjY7E1aJ8hlUA==/cn.uexpo-xB7DjqyolZEYB08lA1idEA==/lib/arm64/libLicensePlate.so (BuildId: 05857e9e5b0e8af297fdc74277cf733086bfa87e)
2023-09-05 16:26:43.706 28210-28210 DEBUG                   crash_dump64                         A        #11 pc 000000000010c1cc  /data/app/~~rFL2u3WIWPjY7E1aJ8hlUA==/cn.uexpo-xB7DjqyolZEYB08lA1idEA==/lib/arm64/libLicensePlate.so (BuildId: 05857e9e5b0e8af297fdc74277cf733086bfa87e)
2023-09-05 16:26:43.707 28210-28210 DEBUG                   crash_dump64                         A        #12 pc 00000000000f8ecc  /data/app/~~rFL2u3WIWPjY7E1aJ8hlUA==/cn.uexpo-xB7DjqyolZEYB08lA1idEA==/lib/arm64/libLicensePlate.so (BuildId: 05857e9e5b0e8af297fdc74277cf733086bfa87e)
2023-09-05 16:26:43.707 28210-28210 DEBUG                   crash_dump64                         A        #13 pc 000000000010cb50  /data/app/~~rFL2u3WIWPjY7E1aJ8hlUA==/cn.uexpo-xB7DjqyolZEYB08lA1idEA==/lib/arm64/libLicensePlate.so (cv::CascadeClassifier::detectMultiScale(cv::_InputArray
                                                                                                    const&, std::vector<cv::Rect_<int>, std::allocator<cv::Rect_<int> > >&, double, int, int, cv::Size_<int>, cv::Size_<int>)+176) (BuildId: 05857e9e5b0e8af297fdc74277cf733086bfa87e)
2023-09-05 16:26:43.707 28210-28210 DEBUG                   crash_dump64                         A        #14 pc 00000000000f0164  /data/app/~~rFL2u3WIWPjY7E1aJ8hlUA==/cn.uexpo-xB7DjqyolZEYB08lA1idEA==/lib/arm64/libLicensePlate.so
                                                                                                    (pr::PlateDetection::plateDetectionRough(cv::Mat, std::vector<pr::PlateInfo, std::allocator<pr::PlateInfo> >&, int, int)+268) (BuildId: 05857e9e5b0e8af297fdc74277cf733086bfa87e)
2023-09-05 16:26:43.707 28210-28210 DEBUG                   crash_dump64                         A        #15 pc 00000000000ebe38  /data/app/~~rFL2u3WIWPjY7E1aJ8hlUA==/cn.uexpo-xB7DjqyolZEYB08lA1idEA==/lib/arm64/libLicensePlate.so
                                                                                                    (pr::PipelinePR::RunPiplineAsImage(cv::Mat, int)+252) (BuildId: 05857e9e5b0e8af297fdc74277cf733086bfa87e)
2023-09-05 16:26:43.707 28210-28210 DEBUG                   crash_dump64                         A        #16 pc 00000000000e4b9c  /data/app/~~rFL2u3WIWPjY7E1aJ8hlUA==/cn.uexpo-xB7DjqyolZEYB08lA1idEA==/lib/arm64/libLicensePlate.so
                                                                                                    (Java_com_shouzhong_licenseplate_PlateRecognition_recognize+392) (BuildId: 05857e9e5b0e8af297fdc74277cf733086bfa87e)
2023-09-05 16:26:43.707 28210-28210 DEBUG                   crash_dump64                         A        #24 pc 000000000042fce0  [anon:dalvik-classes.dex extracted in memory from
                                                                                                    /data/app/~~rFL2u3WIWPjY7E1aJ8hlUA==/cn.uexpo-xB7DjqyolZEYB08lA1idEA==/base.apk] (com.shouzhong.licenseplate.LicensePlateUtils.recognize)
2023-09-05 16:26:43.708 28210-28210 DEBUG                   crash_dump64                         A        #30 pc 0000000000431ebc  [anon:dalvik-classes.dex extracted in memory from
                                                                                                    /data/app/~~rFL2u3WIWPjY7E1aJ8hlUA==/cn.uexpo-xB7DjqyolZEYB08lA1idEA==/base.apk] (com.shouzhong.scanner.ScannerView.onPreviewFrame)
2023-09-05 16:26:43.741 27784-27816 LeakCanary              cn.uexpo                             D  Setting up flushing for Thread[CameraHandlerThread,5,main]
2023-09-05 16:26:43.743 27784-27816 MessageQueue            cn.uexpo                             W  Handler (android.os.Handler) {7d0054e} sending message to a Handler on a dead thread
                                                                                                    java.lang.IllegalStateException: Handler (android.os.Handler) {7d0054e} sending message to a Handler on a dead thread
                                                                                                    	at android.os.MessageQueue.enqueueMessage(MessageQueue.java:560)
                                                                                                    	at android.os.Handler.enqueueMessage(Handler.java:778)
                                                                                                    	at android.os.Handler.sendMessageAtTime(Handler.java:727)
                                                                                                    	at android.os.Handler.sendMessageDelayed(Handler.java:697)
                                                                                                    	at android.os.Handler.post(Handler.java:427)
                                                                                                    	at leakcanary.AndroidLeakFixes$Companion.onEachIdle(AndroidLeakFixes.kt:412)
                                                                                                    	at leakcanary.AndroidLeakFixes$Companion.access$onEachIdle(AndroidLeakFixes.kt:381)
                                                                                                    	at leakcanary.AndroidLeakFixes$FLUSH_HANDLER_THREADS$apply$1.run(AndroidLeakFixes.kt:158)
                                                                                                    	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
                                                                                                    	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:307)
                                                                                                    	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:302)
                                                                                                    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
                                                                                                    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
                                                                                                    	at leakcanary.AndroidLeakFixes$Companion$backgroundExecutor$1$thread$1.run(AndroidLeakFixes.kt:400)

devzwy avatar Sep 05 '23 08:09 devzwy

看起来车牌识别那个库不稳定,其实你都有新能源的库了,应该普通车牌也有,可以用你自己的,我这个非商业的,不稳定而且也不准确,只供学习

shouzhong avatar Sep 21 '23 02:09 shouzhong

车牌那个有源码,如果你对这方面了解的话,可以把代码下下来自己改

shouzhong avatar Sep 21 '23 02:09 shouzhong