mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +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
|
||||
}
|
||||
|
||||
var currentUI *userInterface
|
||||
var (
|
||||
currentUI = &userInterface{
|
||||
sizeChanged: true,
|
||||
origPosX: -1,
|
||||
origPosY: -1,
|
||||
}
|
||||
currentUIInitialized = make(chan struct{})
|
||||
)
|
||||
|
||||
func init() {
|
||||
if err := initialize(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
runtime.LockOSThread()
|
||||
}
|
||||
|
||||
func initialize() error {
|
||||
runtime.LockOSThread()
|
||||
|
||||
if err := glfw.Init(); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -73,19 +76,21 @@ func initialize() error {
|
||||
return err
|
||||
}
|
||||
hideConsoleWindowOnWindows()
|
||||
u := &userInterface{
|
||||
window: window,
|
||||
funcs: make(chan func()),
|
||||
sizeChanged: true,
|
||||
origPosX: -1,
|
||||
origPosY: -1,
|
||||
}
|
||||
u.window.MakeContextCurrent()
|
||||
currentUI = u
|
||||
currentUI.window = window
|
||||
currentUI.funcs = make(chan func())
|
||||
|
||||
currentUI.window.MakeContextCurrent()
|
||||
return nil
|
||||
}
|
||||
|
||||
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.
|
||||
currentUI.setRunning(true)
|
||||
defer func() {
|
||||
@ -243,6 +248,8 @@ func SetCursorVisibility(visible bool) {
|
||||
}
|
||||
|
||||
func Run(width, height int, scale float64, title string, g GraphicsContext) error {
|
||||
<-currentUIInitialized
|
||||
|
||||
u := currentUI
|
||||
// GLContext must be created before setting the screen size, which requires
|
||||
// swapping buffers.
|
||||
|
Loading…
Reference in New Issue
Block a user