Browse Source

fix(camera): app内热路径GetSourceBuffer空返回加守卫,避免后台线程NPE

GetSourceBuffer在相机释放时返回null;GrabAndShow(实时预览/抓帧)与标定存图
两处热路径原先不检查,后台线程NPE会终止进程。加null守卫优雅跳过。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
huangjie 1 tuần trước cách đây
mục cha
commit
6446adb9d6
2 tập tin đã thay đổi với 2 bổ sung0 xóa
  1. 1 0
      MainWindow.Calib.cs
  2. 1 0
      MainWindow.Camera.cs

+ 1 - 0
MainWindow.Calib.cs

@@ -186,6 +186,7 @@ namespace AutoFocusTool
                             Thread.Sleep(150);
                             _camera.GrabRgb();
                             var buf = _camera.GetSourceBuffer();
+                            if (buf == null) { Log($"  well{well} 存图跳过(缓冲为空)"); continue; }
                             string imgPath = $"{resultDir}\\house{houseSn}_well{well}_标定后.bmp";
                             ImageConverter.SaveBmp(buf, _camWidth, _camHeight, imgPath);
                             var bmp = ImageConverter.ToBitmapSource(buf, _camWidth, _camHeight);

+ 1 - 0
MainWindow.Camera.cs

@@ -21,6 +21,7 @@ namespace AutoFocusTool
             int r = _camera.GrabRgb();
             if (r != 0) { Log($"抓帧失败(code={r})"); return false; }
             byte[] buf = _camera.GetSourceBuffer();
+            if (buf == null) { Log("抓帧失败(缓冲为空,可能正在断开)"); return false; }
             _lastFrame = buf;
 
             // 中心 ROI(画面中央 50%)