fix: resolve memory leaks and crash in macOS camera and screen capture
All checks were successful
Deploy on Master Change / deploy (push) Successful in 42s

This commit is contained in:
2026-07-01 13:11:59 +07:00
parent 44888520cb
commit d94c1733be
3 changed files with 96 additions and 28 deletions

View File

@@ -1143,8 +1143,10 @@ func (a *App) connectWS() {
}
err := conn.ReadJSON(&msg)
if err != nil {
log.Printf("[WS] ReadJSON error: %v", err)
break
}
log.Printf("[WS] Received event: %s", msg.Event)
switch msg.Event {
case "start_screenshot_stream":
@@ -1276,26 +1278,39 @@ func (a *App) startWebcamStream() {
go func() {
ticker := time.NewTicker(250 * time.Millisecond)
defer ticker.Stop()
emptyCount := 0
sentCount := 0
for {
select {
case <-ticker.C:
frame := camera.GetFrame()
if frame == "" {
emptyCount++
if emptyCount <= 20 || emptyCount%100 == 0 {
log.Printf("[WS] Webcam: no frame available (empty count: %d)", emptyCount)
}
continue
}
emptyCount = 0
sentCount++
a.mu.Lock()
conn := a.wsConn
a.mu.Unlock()
if conn != nil {
_ = conn.WriteJSON(map[string]any{
err := conn.WriteJSON(map[string]any{
"event": "webcam_stream_frame",
"data": map[string]any{
"imageBuffer": frame,
},
})
if sentCount <= 5 {
log.Printf("[WS] Webcam frame #%d sent (len=%d, err=%v)", sentCount, len(frame), err)
}
} else if sentCount <= 5 {
log.Printf("[WS] Webcam frame #%d: no WS connection", sentCount)
}
case <-a.streamCamStop:
return