cogentcore / core

A free and open source framework for building powerful, fast, elegant 2D and 3D apps that run on macOS, Windows, Linux, iOS, Android, and the web with a single Go codebase, allowing you to Code Once, Run Everywhere.
http://cogentcore.org/core
BSD 3-Clause "New" or "Revised" License
1.74k stars 82 forks source link

Data race when closing main window #1266

Open runrc opened 2 weeks ago

runrc commented 2 weeks ago

Describe the bug

A data race is detected (using the race detector) when the main window is closed.

How to reproduce

Create a simple main window and close it.

Example code

    b := c.NewBody()
    c.NewButton(b).SetText("Hello, World!")
    b.RunMainWindow()

Relevant output

==================
WARNING: DATA RACE
Read at 0x00010665b160 by goroutine 37:
  cogentcore.org/core/system/driver/base.(*AppMulti[go.shape.*uint8]).QuitClean()
      /Users/test/go/pkg/mod/cogentcore.org/core@v0.3.5/system/driver/base/app_multi.go:120 +0x9c
  cogentcore.org/core/system/driver/desktop.(*App).QuitClean()
      <autogenerated>:1 +0x3c
  cogentcore.org/core/system/driver/base.(*App).Quit()
      /Users/test/go/pkg/mod/cogentcore.org/core@v0.3.5/system/driver/base/app.go:174 +0x74
  cogentcore.org/core/system/driver/desktop.(*App).Quit()
      <autogenerated>:1 +0x24
  cogentcore.org/core/core.Wait.func2()
      /Users/test/go/pkg/mod/cogentcore.org/core@v0.3.5/core/renderwindow.go:37 +0x68

Previous write at 0x00010665b160 by goroutine 43:
  cogentcore.org/core/system/driver/base.(*AppMulti[go.shape.*uint8]).RemoveWindow()
      /Users/test/go/pkg/mod/cogentcore.org/core@v0.3.5/system/driver/base/app_multi.go:111 +0xd8
  cogentcore.org/core/system/driver/desktop.(*App).RemoveWindow()
      <autogenerated>:1 +0x4c
  cogentcore.org/core/system/driver/base.(*Window[go.shape.*uint8]).Close()
      /Users/test/go/pkg/mod/cogentcore.org/core@v0.3.5/system/driver/base/window.go:208 +0x164
  cogentcore.org/core/system/driver/desktop.(*Window).Close()
      /Users/test/go/pkg/mod/cogentcore.org/core@v0.3.5/system/driver/desktop/window.go:302 +0x34
  cogentcore.org/core/core.newRenderWindow.func1()
      /Users/test/go/pkg/mod/cogentcore.org/core@v0.3.5/core/renderwindow.go:133 +0x1b8
  cogentcore.org/core/system/driver/base.(*Window[go.shape.*uint8]).CloseReq()
      /Users/test/go/pkg/mod/cogentcore.org/core@v0.3.5/system/driver/base/window.go:185 +0x7c
  cogentcore.org/core/system/driver/desktop.(*Window).OnCloseReq.gowrap1()
      /Users/test/go/pkg/mod/cogentcore.org/core@v0.3.5/system/driver/desktop/window.go:410 +0x40

Goroutine 37 (running) created at:
  cogentcore.org/core/core.Wait()
      /Users/test/go/pkg/mod/cogentcore.org/core@v0.3.5/core/renderwindow.go:34 +0x5c
  cogentcore.org/core/core.(*Body).RunMainWindow()
      /Users/test/go/pkg/mod/cogentcore.org/core@v0.3.5/core/mainstage.go:46 +0x5c
  main.main()
      /Users/test/Dev/test/test.go:38 +0x4a8

Goroutine 43 (running) created at:
  cogentcore.org/core/system/driver/desktop.(*Window).OnCloseReq()
      /Users/test/go/pkg/mod/cogentcore.org/core@v0.3.5/system/driver/desktop/window.go:410 +0xc4
  cogentcore.org/core/system/driver/desktop.(*Window).OnCloseReq-fm()
      <autogenerated>:1 +0x3c
  github.com/go-gl/glfw/v3.3/glfw.goWindowCloseCB()
      /Users/test/go/pkg/mod/github.com/go-gl/glfw/v3.3/glfw@v0.0.0-20240506104042-037f3cc74f2a/window.go:224 +0x54
  _cgoexp_337fa9550dbe_goWindowCloseCB()
      _cgo_gotypes.go:2684 +0x38
  runtime.cgocallbackg1()
      /opt/homebrew/Cellar/go/1.23.2/libexec/src/runtime/cgocall.go:442 +0x22c
  cogentcore.org/core/system/driver/desktop.(*App).MainLoop()
      /Users/test/go/pkg/mod/cogentcore.org/core@v0.3.5/system/driver/desktop/app.go:70 +0x194
  cogentcore.org/core/core.Wait()
      /Users/test/go/pkg/mod/cogentcore.org/core@v0.3.5/core/renderwindow.go:39 +0x80
  cogentcore.org/core/core.(*Body).RunMainWindow()
      /Users/test/go/pkg/mod/cogentcore.org/core@v0.3.5/core/mainstage.go:46 +0x5c
  main.main()
      /Users/test/Dev/test/test.go:38 +0x4a8
==================


### Platform

macOS
kkoreilly commented 2 weeks ago

Thank you for reporting this. I am somewhat busy right now, but I will still be able to fix this soon (ideally within a few days, but definitely within a couple of weeks).