Go version: 1.12.2
Error text: panic: assignment to entry in nil map
I’m aware that assigning to just a var myMap map[string]int
leads to an issue with assignment to a nil map and that you have to do myMap := make(map[string]int)
but I seem to be having the same issue with a map that I’ve already assigned to. Below is the stripped down code. Beware that I’ve added a bunch of superfluous stuff as a means of troubleshooting (though I tried to rip a lot of that out):
for frm := range input {
go func() {
detMap := make(map[string][]image.Rectangle)
tmpRect := []image.Rectangle{image.Rectangle{image.Point{0, 0}, image.Point{1, 1}}}
detMap["init"] = tmpRect
tmpImg, _, _, _, detMap, sublError = imageFrames.Sublimate(frm)
rects := det.DetectMultiScale(tmpImg)
detMap[fname] = rects
frm.Detections = detMap
output <- frm
return
}()
}
I added “tmpRect” in an attempt to make sure that detMap is actually not nil. ImageFrames.Sublimate() is below:
func Sublimate(inFrm Frame) (gocv.Mat, string, []byte, map[int]image.Rectangle, map[string][]image.Rectangle, error) {
retMap := make(map[string][]image.Rectangle)
retMot := make(map[int]image.Rectangle)
retMap = inFrm.Detections
retMot = inFrm.MotionMap
retMat, err := gocv.NewMatFromBytes(inFrm.Wid, inFrm.Hei, inFrm.Type, inFrm.MatBytes)
return retMat, inFrm.UserName, inFrm.UserHash, retMot, retMap, err
}
I get the same issue if I just do tmpImg, _, _, _, detMap, sublError := imageFrames.Sublimate(frm)
without creating the map beforehand.