Home > Article > Backend Development > Intermittent NSInternalInconsistencyException when using gocv on macOS
I have code using gocv (Provides go language bindings for opencv). It just draws some rectangles on the image and displays the result.
func main() { resp, err := http.get("http://localhost:6060/template-match") if err != nil { panic(err) } defer resp.body.close() body, err := ioutil.readall(resp.body) if err != nil { panic(err) } fmt.println(string(body)) var data response err = json.unmarshal(body, &data) if err != nil { panic(err) } srcimage := gocv.imread("./images/src1.jpg", gocv.imreadcolor) for i := 0; i < len(data.data); i++ { gocv.rectangle(&srcimage, data.data[i], color.rgba{r: 255}, 2) } window := gocv.newwindow("match-result") window.imshow(srcimage) gocv.waitkey(0) fmt.println(data.data, data.msg)
I get this error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the Main Thread!'
I'm really confused because this error doesn't happen every time
I haven't used this library but it looks like this A Known Issue - Also, since you mentioned that it only happens sometimes, it sounds like the bug does depend on the thread context. The answers there (from the library author) point to https://github.com/golang/go/wiki/lockosthread, so your main package should implement something similar
func init() { runtime.LockOSThread() }
The above is the detailed content of Intermittent NSInternalInconsistencyException when using gocv on macOS. For more information, please follow other related articles on the PHP Chinese website!