core icon indicating copy to clipboard operation
core copied to clipboard

Data race when closing main window

Open runrc opened this issue 1 year ago • 1 comments

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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/system/driver/base/window.go:208 +0x164
  cogentcore.org/core/system/driver/desktop.(*Window).Close()
      /Users/test/go/pkg/mod/cogentcore.org/[email protected]/system/driver/desktop/window.go:302 +0x34
  cogentcore.org/core/core.newRenderWindow.func1()
      /Users/test/go/pkg/mod/cogentcore.org/[email protected]/core/renderwindow.go:133 +0x1b8
  cogentcore.org/core/system/driver/base.(*Window[go.shape.*uint8]).CloseReq()
      /Users/test/go/pkg/mod/cogentcore.org/[email protected]/system/driver/base/window.go:185 +0x7c
  cogentcore.org/core/system/driver/desktop.(*Window).OnCloseReq.gowrap1()
      /Users/test/go/pkg/mod/cogentcore.org/[email protected]/system/driver/desktop/window.go:410 +0x40

Goroutine 37 (running) created at:
  cogentcore.org/core/core.Wait()
      /Users/test/go/pkg/mod/cogentcore.org/[email protected]/core/renderwindow.go:34 +0x5c
  cogentcore.org/core/core.(*Body).RunMainWindow()
      /Users/test/go/pkg/mod/cogentcore.org/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/system/driver/desktop/app.go:70 +0x194
  cogentcore.org/core/core.Wait()
      /Users/test/go/pkg/mod/cogentcore.org/[email protected]/core/renderwindow.go:39 +0x80
  cogentcore.org/core/core.(*Body).RunMainWindow()
      /Users/test/go/pkg/mod/cogentcore.org/[email protected]/core/mainstage.go:46 +0x5c
  main.main()
      /Users/test/Dev/test/test.go:38 +0x4a8
==================


### Platform

macOS

runrc avatar Oct 21 '24 16:10 runrc

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).

kkoreilly avatar Oct 21 '24 19:10 kkoreilly