~eliasnaur/gio

1ad59f562a1f09865e4a908f4ac65934cebc9242 — Elias Naur a month ago d9ddbe6
app: close the window before reporting a GPU error

When a GPU error occurs forcing the reporting of a DestroyEvent is not
appropriate, because the backend that controls the underlying window
is not aware of the error and will continue to report events.

Replace the crude DestroyEvent by stashing the error and asking the
window nicely to close. The, report the stashed error in the
otherwise regular DestroyEvent.

Hopefully, this second attempt fixes #603.

Fixes: https://todo.sr.ht/~eliasnaur/gio/603
Signed-off-by: Elias Naur <mail@eliasnaur.com>
1 files changed, 8 insertions(+), 1 deletions(-)

M app/window.go
M app/window.go => app/window.go +8 -1
@@ 89,6 89,9 @@ type Window struct {
	}
	imeState editorState
	driver   driver
	// gpuErr tracks the GPU error that is to be reported when
	// the window is closed.
	gpuErr error

	// invMu protects mayInvalidate.
	invMu         sync.Mutex


@@ 227,7 230,8 @@ func (w *Window) processFrame(frame *op.Ops, ack chan<- struct{}) {
	w.lastFrame.deco.Add(wrapper)
	if err := w.validateAndProcess(w.lastFrame.size, w.lastFrame.sync, wrapper, ack); err != nil {
		w.destroyGPU()
		w.driver.ProcessEvent(DestroyEvent{Err: err})
		w.gpuErr = err
		w.driver.Perform(system.ActionClose)
		return
	}
	w.updateState()


@@ 637,6 641,9 @@ func (w *Window) processEvent(e event.Event) bool {
		e2.Size = e2.Size.Sub(offset)
		w.coalesced.frame = &e2
	case DestroyEvent:
		if w.gpuErr != nil {
			e2.Err = w.gpuErr
		}
		w.destroyGPU()
		w.invMu.Lock()
		w.mayInvalidate = false