空指针导致程序出错

This commit is contained in:
lijun 2025-01-15 23:04:32 +08:00
parent 1c581654f4
commit 3a65f8c468
1 changed files with 11 additions and 1 deletions

View File

@ -169,7 +169,13 @@ func subscribeAndHandleMessagesV3(ws *websocket.Conn, device_id int) {
if img.Empty() {
fmt.Println("device:%d img is empty!", device_id)
} else {
buf, _ := gocv.IMEncode(".jpg", img)
//gocv.Matrix转为jpeg
buf, err := gocv.IMEncode(".jpg", img)
if err != nil {
fmt.Println("img encode err:", err)
worker.SetRedisSetRemove(online_conn_key, con_id)
goto end
}
buf1 := buf.GetBytes()
err2 := ws.WriteMessage(websocket.BinaryMessage, buf1)
@ -193,6 +199,10 @@ func subscribeAndHandleMessagesV3(ws *websocket.Conn, device_id int) {
}
time.Sleep(100 * time.Millisecond)
t_count++
err := img.Close()
if err != nil {
fmt.Println("close img err:", err)
}
}
end: