Skip to content

Commit

Permalink
Guard for nil when closing windows
Browse files Browse the repository at this point in the history
Fixes: #3870
  • Loading branch information
imran-iq authored and andydotxyz committed May 9, 2023
1 parent ec0d80e commit 4b01822
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion internal/driver/glfw/window_desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,9 @@ func (w *window) refresh(_ *glfw.Window) {
}

func (w *window) closed(viewport *glfw.Window) {
viewport.SetShouldClose(false) // reset the closed flag until we check the veto in processClosed
if viewport != nil {
viewport.SetShouldClose(false) // reset the closed flag until we check the veto in processClosed
}

w.processClosed()
}
Expand Down
6 changes: 6 additions & 0 deletions internal/driver/glfw/window_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1720,6 +1720,12 @@ func TestWindow_CloseInterception(t *testing.T) {
})
}

func TestWindow_ClosedBeforeShow(t *testing.T) {
w := createWindow("Test").(*window)
// viewport will be nil if window is closed before show
assert.NotPanics(t, func() { w.closed(nil) })
}

func TestWindow_SetContent_Twice(t *testing.T) {
w := createWindow("Test").(*window)

Expand Down

0 comments on commit 4b01822

Please sign in to comment.