mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
internal/ui: refactoring: (*monitors).update must be called from the main thread
In the current implementation, (*monitors).update is not called from other threads, but the current code is fragile.
This commit is contained in:
parent
e40268c3ca
commit
92424319a2
@ -63,7 +63,7 @@ var theMonitors monitors
|
||||
|
||||
func (m *monitors) append(ms []*Monitor) []*Monitor {
|
||||
if atomic.LoadInt32(&m.updateCalled) == 0 {
|
||||
m.update()
|
||||
panic("ui: (*monitors).update must be called before (*monitors).append is called")
|
||||
}
|
||||
|
||||
m.m.Lock()
|
||||
@ -91,6 +91,7 @@ func (m *monitors) monitorFromID(id int) *Monitor {
|
||||
return m.monitors[id]
|
||||
}
|
||||
|
||||
// update must be called from the main thread.
|
||||
func (m *monitors) update() {
|
||||
glfwMonitors := glfw.GetMonitors()
|
||||
newMonitors := make([]*Monitor, 0, len(glfwMonitors))
|
||||
|
@ -155,13 +155,13 @@ func init() {
|
||||
|
||||
func init() {
|
||||
hideConsoleWindowOnWindows()
|
||||
|
||||
if err := initialize(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
glfw.SetMonitorCallback(glfw.ToMonitorCallback(func(monitor *glfw.Monitor, event glfw.PeripheralEvent) {
|
||||
theMonitors.update()
|
||||
}))
|
||||
theMonitors.update()
|
||||
}
|
||||
|
||||
var glfwSystemCursors = map[CursorShape]*glfw.Cursor{}
|
||||
@ -174,6 +174,9 @@ func initialize() error {
|
||||
glfw.WindowHint(glfw.Visible, glfw.False)
|
||||
glfw.WindowHint(glfw.ClientAPI, glfw.NoAPI)
|
||||
|
||||
// Update the monitor first. The monitor state is depended on various functions like initialMonitorByOS.
|
||||
theMonitors.update()
|
||||
|
||||
m, err := initialMonitorByOS()
|
||||
if err != nil {
|
||||
return err
|
||||
|
Loading…
Reference in New Issue
Block a user