mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-04-30 15:54:32 +08:00
Prevent a possible memory leak while showing a stuck camera stream
This commit is contained in:
parent
20ffb0cd6d
commit
7e60d459b4
@ -326,6 +326,9 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
|
||||
return True
|
||||
|
||||
def _stopCamera(self):
|
||||
self._stream_buffer = b""
|
||||
self._stream_buffer_start_index = -1
|
||||
|
||||
if self._camera_timer.isActive():
|
||||
self._camera_timer.stop()
|
||||
if self._image_reply:
|
||||
@ -1165,6 +1168,12 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
|
||||
return
|
||||
self._stream_buffer += self._image_reply.readAll()
|
||||
|
||||
if len(self._stream_buffer) > 2000000: # No single camera frame should be 2 Mb or larger
|
||||
Logger.log("w", "MJPEG buffer exceeds reasonable size. Restarting stream...")
|
||||
self._stopCamera() # resets stream buffer and start index
|
||||
self._startCamera()
|
||||
return
|
||||
|
||||
if self._stream_buffer_start_index == -1:
|
||||
self._stream_buffer_start_index = self._stream_buffer.indexOf(b'\xff\xd8')
|
||||
stream_buffer_end_index = self._stream_buffer.lastIndexOf(b'\xff\xd9')
|
||||
|
Loading…
x
Reference in New Issue
Block a user