日志输出,空指针导致程序出错,重写释放逻辑
This commit is contained in:
parent
535e61dfa6
commit
5b3ef982eb
|
|
@ -164,7 +164,8 @@ func subscribeAndHandleMessagesV3(ws *websocket.Conn, device_id int) {
|
||||||
t_count := 0
|
t_count := 0
|
||||||
for {
|
for {
|
||||||
//从service获取当前帧
|
//从service获取当前帧
|
||||||
img, c := service.GetDeviceCurrentFrame(device_id)
|
var img gocv.Mat
|
||||||
|
c := service.GetDeviceCurrentFrameV2(&img, device_id)
|
||||||
if c != count {
|
if c != count {
|
||||||
//将img转[]byte
|
//将img转[]byte
|
||||||
if img.Empty() {
|
if img.Empty() {
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,47 @@ func SetDeviceCurrentFrame(frame gocv.Mat, device_id int) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetDeviceCurrentFrameV2(frame *gocv.Mat, deviceId int) int {
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
log.Printf("设备:%d 错误: %v\n", deviceId, err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
//获取读写锁
|
||||||
|
mutex_, ok := DeviceRWMap.Load(deviceId)
|
||||||
|
if !ok {
|
||||||
|
log.Printf("DeviceRWMap 读写锁不存在,device_id: %d \n", deviceId)
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
mutex, ok := mutex_.(*sync.RWMutex)
|
||||||
|
if !ok {
|
||||||
|
log.Printf("DeviceRWMap 存储的不是 *sync.RWMutex 类型,device_id: %d \n", deviceId)
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
mutex.RLock()
|
||||||
|
defer mutex.RUnlock()
|
||||||
|
var frame_ gocv.Mat
|
||||||
|
//获取当前帧
|
||||||
|
frameIface, ok := DeviceCurrentFrameMap.Load(deviceId)
|
||||||
|
if !ok {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
frame_, ok = frameIface.(gocv.Mat)
|
||||||
|
if !ok {
|
||||||
|
log.Printf("DeviceCurrentFrameMap 存储的不是 gocv.Mat 类型,device_id: %d \n", deviceId)
|
||||||
|
}
|
||||||
|
*frame = frame_
|
||||||
|
frame_countIface, ok := DeviceFrameCount.Load(deviceId)
|
||||||
|
if !ok {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
frame_count, ok := frame_countIface.(int)
|
||||||
|
if !ok {
|
||||||
|
log.Printf("DeviceFrameCount 存储的不是 int 类型,device_id: %d", deviceId)
|
||||||
|
}
|
||||||
|
return frame_count
|
||||||
|
}
|
||||||
|
|
||||||
func GetDeviceCurrentFrame(deviceId int) (gocv.Mat, int) {
|
func GetDeviceCurrentFrame(deviceId int) (gocv.Mat, int) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := recover(); err != nil {
|
if err := recover(); err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue