~eliasnaur/gio#596: 
[Windows] Rapidly invalidating while initializing window can break the window

On windows, the following program never generates a frame event, despite creating and displaying an application window. Additionally, it crashes with a deadlock when you close the window (at least usually).

package main

import (
        "log"
        "os"

        "gioui.org/app"
        "gioui.org/io/system"
)

func main() {
        go func() {
                w := new(app.Window)
                w.Perform(system.ActionRaise)
                if err := loop(w); err != nil {
                        log.Fatal(err)
                }
                os.Exit(0)
        }()
        app.Main()
}

func loop(w *app.Window) error {
        go func() {
                for {
                        w.Invalidate()
                }
        }()
        for {
                switch e := w.Event().(type) {
                case app.DestroyEvent:
                        return e.Err
                case app.FrameEvent:
                        // Crash if we actually get a frame event, to make it easier
                        // to spot a successful run.
                        log.Fatal(e)
                }
        }
}

The above was tested against Gio commit 8fb6d3da.

I discovered this (and some potentially related bugs) while debugging a custom renderer window that would sometimes open and be utterly broken (spinning in a render tightloop without emitting frame events).

It seems like there is some kind of race in window initialization. If an invalidate (or perhaps several) occur at just the right time, the event loop doesn't run correctly and never emits frame events. Doing a window.Perform either makes the problem happen or makes it much more likely.

The same example program works as expected on Linux (X11 and Wayland). It exits because it got a frame event.

Status
RESOLVED FIXED
Submitter
~whereswaldon
Assigned to
No-one
Submitted
5 months ago
Updated
5 months ago
Labels
No labels applied.

~eliasnaur REPORTED FIXED 5 months ago

Elias Naur referenced this ticket in commit bce5ffc.

~eliasnaur 5 months ago

Elias Naur referenced this ticket in commit 1b283cb.

~eliasnaur 5 months ago

Elias Naur referenced this ticket in commit 632a44d.

~eliasnaur 5 months ago

Elias Naur referenced this ticket in commit 072d68c.

~eliasnaur 5 months ago

Elias Naur referenced this ticket in commit e8ba786.

~eliasnaur 5 months ago

Elias Naur referenced this ticket in commit 4e2d418.

~eliasnaur 5 months ago

Elias Naur referenced this ticket in commit 3f671af.

Register here or Log in to comment, or comment via email.