Hopefully fixed lockup bug.

This commit is contained in:
Storm Dragon
2025-08-16 19:57:19 -04:00
parent 022b9ba048
commit c86921ea65
5 changed files with 228 additions and 111 deletions

View File

@@ -81,6 +81,7 @@ class CallBacks(dict):
for func in self[callback]:
if callback is PYMUMBLE_CLBK_TEXTMESSAGERECEIVED:
thr = threading.Thread(target=func, args=pos_parameters)
thr.daemon = True # Fix critical memory leak - ensure thread cleanup
thr.start()
else:
func(*pos_parameters)

View File

@@ -161,14 +161,27 @@ class SoundOutput:
samples = int(self.encoder_framesize * PYMUMBLE_SAMPLERATE * 2 * self.channels) # number of samples in an encoder frame
self.lock.acquire()
if len(self.pcm) and len(self.pcm[-1]) < samples:
initial_offset = samples - len(self.pcm[-1])
self.pcm[-1] += pcm[:initial_offset]
else:
initial_offset = 0
for i in range(initial_offset, len(pcm), samples):
self.pcm.append(pcm[i:i + samples])
self.lock.release()
try:
# Prevent unbounded buffer growth - limit to 10 seconds of audio
max_buffer_seconds = 10.0
max_buffer_frames = int(max_buffer_seconds / self.encoder_framesize)
# If buffer is too full, drop oldest frames to prevent memory leak
if len(self.pcm) > max_buffer_frames:
frames_to_drop = len(self.pcm) - max_buffer_frames
self.pcm = self.pcm[frames_to_drop:]
if hasattr(self, 'Log'):
self.Log.warning(f"Audio buffer overflow, dropped {frames_to_drop} frames")
if len(self.pcm) and len(self.pcm[-1]) < samples:
initial_offset = samples - len(self.pcm[-1])
self.pcm[-1] += pcm[:initial_offset]
else:
initial_offset = 0
for i in range(initial_offset, len(pcm), samples):
self.pcm.append(pcm[i:i + samples])
finally:
self.lock.release()
def clear_buffer(self):
self.lock.acquire()