日志输出,空指针导致程序出错-测试获取帧
This commit is contained in:
parent
75d8492618
commit
647def1279
|
|
@ -40,35 +40,41 @@ func SetDeviceCurrentFrame(frame gocv.Mat, device_id int) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func GetDeviceCurrentFrame(device_id int) (gocv.Mat, int) {
|
||||
func GetDeviceCurrentFrame(deviceId int) (gocv.Mat, int) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
log.Printf("设备:%d 错误: %v\n", deviceId, err)
|
||||
}
|
||||
}()
|
||||
|
||||
//获取读写锁
|
||||
mutex_, ok := DeviceRWMap.Load(device_id)
|
||||
mutex_, ok := DeviceRWMap.Load(deviceId)
|
||||
if !ok {
|
||||
return gocv.NewMat(), -1
|
||||
}
|
||||
mutex, ok := mutex_.(*sync.RWMutex)
|
||||
if !ok {
|
||||
log.Printf("DeviceRWMap 存储的不是 *sync.RWMutex 类型,device_id: %d", device_id)
|
||||
log.Printf("DeviceRWMap 存储的不是 *sync.RWMutex 类型,device_id: %d", deviceId)
|
||||
return gocv.NewMat(), -1
|
||||
}
|
||||
mutex.RLock()
|
||||
defer mutex.RUnlock()
|
||||
//获取当前帧
|
||||
frameIface, ok := DeviceCurrentFrameMap.Load(device_id)
|
||||
frameIface, ok := DeviceCurrentFrameMap.Load(deviceId)
|
||||
if !ok {
|
||||
return gocv.NewMat(), -1
|
||||
}
|
||||
frame, ok := frameIface.(gocv.Mat)
|
||||
if !ok {
|
||||
log.Printf("DeviceCurrentFrameMap 存储的不是 gocv.Mat 类型,device_id: %d", device_id)
|
||||
log.Printf("DeviceCurrentFrameMap 存储的不是 gocv.Mat 类型,device_id: %d", deviceId)
|
||||
}
|
||||
frame_countIface, ok := DeviceFrameCount.Load(device_id)
|
||||
frame_countIface, ok := DeviceFrameCount.Load(deviceId)
|
||||
if !ok {
|
||||
return gocv.NewMat(), -1
|
||||
}
|
||||
frame_count, ok := frame_countIface.(int)
|
||||
if !ok {
|
||||
log.Printf("DeviceFrameCount 存储的不是 int 类型,device_id: %d", device_id)
|
||||
log.Printf("DeviceFrameCount 存储的不是 int 类型,device_id: %d", deviceId)
|
||||
}
|
||||
return frame, frame_count
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue