mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 19:28:57 +01:00
ui: Delay initialize until Run (#397)
This commit is contained in:
parent
ee98148b54
commit
807d03eb3b
@ -48,17 +48,20 @@ type userInterface struct {
|
|||||||
m sync.Mutex
|
m sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentUI *userInterface
|
var (
|
||||||
|
currentUI = &userInterface{
|
||||||
|
sizeChanged: true,
|
||||||
|
origPosX: -1,
|
||||||
|
origPosY: -1,
|
||||||
|
}
|
||||||
|
currentUIInitialized = make(chan struct{})
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if err := initialize(); err != nil {
|
runtime.LockOSThread()
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func initialize() error {
|
func initialize() error {
|
||||||
runtime.LockOSThread()
|
|
||||||
|
|
||||||
if err := glfw.Init(); err != nil {
|
if err := glfw.Init(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -73,19 +76,21 @@ func initialize() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
hideConsoleWindowOnWindows()
|
hideConsoleWindowOnWindows()
|
||||||
u := &userInterface{
|
currentUI.window = window
|
||||||
window: window,
|
currentUI.funcs = make(chan func())
|
||||||
funcs: make(chan func()),
|
|
||||||
sizeChanged: true,
|
currentUI.window.MakeContextCurrent()
|
||||||
origPosX: -1,
|
|
||||||
origPosY: -1,
|
|
||||||
}
|
|
||||||
u.window.MakeContextCurrent()
|
|
||||||
currentUI = u
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunMainThreadLoop(ch <-chan error) error {
|
func RunMainThreadLoop(ch <-chan error) error {
|
||||||
|
// This must be called on the main thread.
|
||||||
|
|
||||||
|
if err := initialize(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
close(currentUIInitialized)
|
||||||
|
|
||||||
// TODO: Check this is done on the main thread.
|
// TODO: Check this is done on the main thread.
|
||||||
currentUI.setRunning(true)
|
currentUI.setRunning(true)
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -243,6 +248,8 @@ func SetCursorVisibility(visible bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Run(width, height int, scale float64, title string, g GraphicsContext) error {
|
func Run(width, height int, scale float64, title string, g GraphicsContext) error {
|
||||||
|
<-currentUIInitialized
|
||||||
|
|
||||||
u := currentUI
|
u := currentUI
|
||||||
// GLContext must be created before setting the screen size, which requires
|
// GLContext must be created before setting the screen size, which requires
|
||||||
// swapping buffers.
|
// swapping buffers.
|
||||||
|
Loading…
Reference in New Issue
Block a user