产测死机问题修复
authorxue <2144439972@qq.com>
Wed, 18 Mar 2026 09:03:44 +0000 (17:03 +0800)
committerxue <2144439972@qq.com>
Wed, 18 Mar 2026 09:03:44 +0000 (17:03 +0800)
code/sdk/zhihui/UI/producttest/src/testGPS.cpp
code/sdk/zhihui/UI/producttest/src/testold.cpp

index 6268510..67ed930 100644 (file)
@@ -246,7 +246,12 @@ namespace OHOS
 
     void gpsdataTimerCallBackproc()
     {
-         GraphicService::GetInstance()->PostGraphicEvent(std::bind(&testGPSView::gpsdataTimerCallBack,testGPSView::GetInstance()));
+        // 定时器是全局的,可能在界面已销毁后仍然触发一次,这里要做空指针防护
+        testGPSView *view = testGPSView::GetInstance();
+        if (view == nullptr) {
+            return;
+        }
+        GraphicService::GetInstance()->PostGraphicEvent(std::bind(&testGPSView::gpsdataTimerCallBack, view));
     }
 
     
index 55ee56b..97d50bb 100644 (file)
@@ -18,7 +18,8 @@ namespace OHOS
 
     static testoldView *g_pSystemAboutTheWatchView{nullptr};
     static osTimerId_t  g_aging_timer=NULL;
-
+    static volatile bool g_aging_view_valid = false;  /* 防止定时器回调在界面销毁后访问已释放控件导致 Load access fault */
+   
 #ifdef SUPPORT_FACTORY_SERVICE
     static ble_aging_t aging_t;
 #endif
@@ -69,6 +70,7 @@ namespace OHOS
     {
         if(testoldScrollView)
         {
+            g_aging_view_valid = false;
             testoldScrollView->RemoveAll();
 
             if (g_aging_timer != NULL) 
@@ -266,10 +268,14 @@ namespace OHOS
     {
         do_custom_fileoperate_service_check_msg(CUSTOM_FILEOPERATE_MSG_TYPE_AGING_DATA_READ, NULL, 0);
         LOS_Msleep(500);
-#ifdef SUPPORT_FACTORY_SERVICE
+        if (!g_aging_view_valid) {
+            return;  /* 界面已退出或正在清理,避免 use-after-free 导致 Load access fault */
+        }
         factorytest_get_aging_data(&aging_t);
-#endif
         OHOS::testoldView *pview = OHOS::testoldView::GetInstance();
+        if (pview == nullptr || !g_aging_view_valid) {
+            return;
+        }
         pview->setdata();
     }
 
@@ -594,6 +600,7 @@ namespace OHOS
         testoldScrollView->SetTouchable(true);
         testoldScrollView->SetDraggable(true);
 
+        g_aging_view_valid = true;  /* 界面已就绪,允许定时器回调访问 UI */
         g_aging_timer = osTimerNew((osTimerFunc_t)msgupdateTimerCallBack, osTimerPeriodic, NULL, NULL);
 
         osStatus_t ret = osTimerStart(g_aging_timer, 1000 * 60 * 10);