Intermittent NSInternalInconsistencyException when using gocv on macOS

WBOY
Release: 2024-02-06 11:00:07
forward
992 people have browsed it

在 macOS 上使用 gocv 时间歇性出现 NSInternalInconsistencyException

Question content

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)
Copy after login

I get this error:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the Main Thread!'
Copy after login

I'm really confused because this error doesn't happen every time


Correct answer


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()
}
Copy after login

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!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template