fix: synchronize close state in glfw window (#3874)#6308
Conversation
|
Can you confirm which goroutine you are referring to? All Fyne calls should operate on the same thread... |
Even though Fyne pins UI work to a single thread, application code still routinely can calls Several other
That creates a race where:
The The second test exposes a separate lifetime issue unrelated to threading.
|
Application code should be wrapped in |
Currently, but it will not be supported forever. The locks in place currently are for the transition period only. Apps using 2.8 (after release) that have not migrated will see the following message: We started this migration in 2.6 and has been mentioned in the release notes. |
7968651 to
b3b6dde
Compare
|
Thanks, that made me realize I misunderstood fyne's threading and window-lifecycle guarantees. The mutex was based on a wrong assumption, so I've removed it. I'd still like to keep the stale-pointer fix: after |
andydotxyz
left a comment
There was a problem hiding this comment.
Thanks, I agree it makes sense to keep in this safety.
But can you reduce the comments to the essentials? Otherwise they rot and/or get misleading.
| return w.viewport | ||
| } | ||
|
|
||
| // destroyViewport destroys the underlying GLFW window and clears the pointer |
There was a problem hiding this comment.
Can you make this more succinct?
It reads AI generated because it refers to behaviour in other methods as well.
The docs on a method should describe what it does only - not how others respond to it.
Also no need to mention it has the same threading semantics as the rest of the code in the same file.
Description:
The goroutine and main thread both touched same fields (
closing,viewport) without any lock, andviewport.Destroy()left pointer in place ? so next frame called methods on an already destroyed window.What changed:
sync.RWMutexto the window that guardsclosingandviewport.isClosing(),view()andClose()now read and write those fields under the lock.RunWithContexttakes a single snapshot of viewport and skips frame if the window is gone.destroyViewport()clears pointer before destroying window; close path uses it.Tests added in
internal/driver/glfw/window_test.go:Close()while another goroutine reads window state. Without fix it fails under-race.Fixes #3874
Checklist: