Skip to content

Commit 603d082

Browse files
authored
RSDK-9602: Prevent lazyEncodedImage.Bounds from getting gostream into a panic loop. (viamrobotics#4650)
1 parent fb3df2c commit 603d082

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

gostream/stream.go

+26-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package gostream
44
import (
55
"context"
66
"errors"
7+
"fmt"
78
"image"
89
"sync"
910
"time"
@@ -269,7 +270,31 @@ func (bs *basicStream) processInputFrames() {
269270
if frame, ok := framePair.Media.(*rimage.LazyEncodedImage); ok && frame.MIMEType() == utils2.MimeTypeH264 {
270271
encodedFrame = frame.RawData() // nothing to do; already encoded
271272
} else {
272-
bounds := framePair.Media.Bounds()
273+
var bounds image.Rectangle
274+
var boundsError any
275+
func() {
276+
defer func() {
277+
if paniced := recover(); paniced != nil {
278+
boundsError = paniced
279+
}
280+
}()
281+
282+
bounds = framePair.Media.Bounds()
283+
}()
284+
285+
if boundsError != nil {
286+
bs.logger.Errorw("Getting frame bounds failed", "err", fmt.Sprintf("%s", boundsError))
287+
// Dan: It's unclear why we get this error. There's reason to believe this pops
288+
// up when a camera is reconfigured/removed. In which case I'd expect the
289+
// `basicStream` to soon be closed. Making this `initErr = true` assignment to
290+
// exit the `processInputFrames` goroutine unnecessary. But I'm choosing to be
291+
// conservative for the worst case. Where we may be in a permanent bad state and
292+
// (until we understand the problem better) we would spew logs until the user
293+
// stops the stream.
294+
initErr = true
295+
return
296+
}
297+
273298
newDx, newDy := bounds.Dx(), bounds.Dy()
274299
if bs.videoEncoder == nil || dx != newDx || dy != newDy {
275300
dx, dy = newDx, newDy

0 commit comments

Comments
 (0)