Skip to content

Commit abed9d1

Browse files
committed
Cancel probe worker and copy QImage
Ensure the probe worker is cleanly stopped when shutting down: call request_cancel(), wait (up to 1500ms), and clear the _probe_worker reference to avoid dangling threads. Also make a copy of the QImage created from the frame buffer (QImage(...).copy()) so the Qt image doesn't reference the underlying frame memory, preventing use-after-free crashes or visual corruption.
1 parent 4404f78 commit abed9d1

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

dlclivegui/gui/camera_config_dialog.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1662,6 +1662,13 @@ def reject(self) -> None:
16621662
pass
16631663
self._scan_worker.wait(1500)
16641664
self._scan_worker = None
1665+
if getattr(self, "_probe_worker", None) and self._probe_worker.isRunning():
1666+
try:
1667+
self._probe_worker.request_cancel()
1668+
except Exception:
1669+
pass
1670+
self._probe_worker.wait(1500)
1671+
self._probe_worker = None
16651672

16661673
self._hide_scan_overlay()
16671674
self.scan_progress.setVisible(False)
@@ -2027,7 +2034,7 @@ def _update_preview(self) -> None:
20272034

20282035
h, w, ch = frame.shape
20292036
bytes_per_line = ch * w
2030-
q_img = QImage(frame.data, w, h, bytes_per_line, QImage.Format.Format_RGB888)
2037+
q_img = QImage(frame.data, w, h, bytes_per_line, QImage.Format.Format_RGB888).copy()
20312038
self.preview_label.setPixmap(QPixmap.fromImage(q_img))
20322039

20332040
except Exception as exc:

0 commit comments

Comments
 (0)