mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
ui: initFullscreen should always be protected by lock
This commit is contained in:
parent
434d5bb00b
commit
1021521591
@ -109,14 +109,28 @@ func RunMainThreadLoop(ch <-chan error) error {
|
|||||||
|
|
||||||
func (u *userInterface) isRunning() bool {
|
func (u *userInterface) isRunning() bool {
|
||||||
u.m.Lock()
|
u.m.Lock()
|
||||||
defer u.m.Unlock()
|
v := u.running
|
||||||
return u.running
|
u.m.Unlock()
|
||||||
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterface) setRunning(running bool) {
|
func (u *userInterface) setRunning(running bool) {
|
||||||
u.m.Lock()
|
u.m.Lock()
|
||||||
defer u.m.Unlock()
|
|
||||||
u.running = running
|
u.running = running
|
||||||
|
u.m.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *userInterface) isInitFullscreen() bool {
|
||||||
|
u.m.Lock()
|
||||||
|
v := u.initFullscreen
|
||||||
|
u.m.Unlock()
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *userInterface) setInitFullscreen(initFullscreen bool) {
|
||||||
|
u.m.Lock()
|
||||||
|
u.initFullscreen = initFullscreen
|
||||||
|
u.m.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterface) runOnMainThread(f func() error) error {
|
func (u *userInterface) runOnMainThread(f func() error) error {
|
||||||
@ -163,9 +177,7 @@ func SetScreenScale(scale float64) bool {
|
|||||||
func SetFullscreen(fullscreen bool) {
|
func SetFullscreen(fullscreen bool) {
|
||||||
u := currentUI
|
u := currentUI
|
||||||
if !u.isRunning() {
|
if !u.isRunning() {
|
||||||
u.m.Lock()
|
u.setInitFullscreen(fullscreen)
|
||||||
u.initFullscreen = fullscreen
|
|
||||||
u.m.Unlock()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_ = u.runOnMainThread(func() error {
|
_ = u.runOnMainThread(func() error {
|
||||||
@ -191,10 +203,7 @@ func ScreenScale() float64 {
|
|||||||
func IsFullscreen() bool {
|
func IsFullscreen() bool {
|
||||||
u := currentUI
|
u := currentUI
|
||||||
if !u.isRunning() {
|
if !u.isRunning() {
|
||||||
u.m.Lock()
|
return u.isInitFullscreen()
|
||||||
v := u.initFullscreen
|
|
||||||
u.m.Unlock()
|
|
||||||
return v
|
|
||||||
}
|
}
|
||||||
f := false
|
f := false
|
||||||
_ = u.runOnMainThread(func() error {
|
_ = u.runOnMainThread(func() error {
|
||||||
@ -338,10 +347,10 @@ func (u *userInterface) update(g GraphicsContext) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_ = u.runOnMainThread(func() error {
|
_ = u.runOnMainThread(func() error {
|
||||||
if u.initFullscreen {
|
if u.isInitFullscreen() {
|
||||||
u := currentUI
|
u := currentUI
|
||||||
u.setScreenSize(u.width, u.height, u.scale, true)
|
u.setScreenSize(u.width, u.height, u.scale, true)
|
||||||
u.initFullscreen = false
|
u.setInitFullscreen(false)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user