mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 19:28:57 +01:00
loop: Prevent re-entering to Run
This commit is contained in:
parent
a329f7939d
commit
857bc1ed51
@ -15,6 +15,7 @@
|
|||||||
package loop
|
package loop
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -40,7 +41,7 @@ type runContext struct {
|
|||||||
m sync.RWMutex
|
m sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentRunContext runContext
|
var currentRunContext *runContext
|
||||||
|
|
||||||
func (c *runContext) startRunning() {
|
func (c *runContext) startRunning() {
|
||||||
c.m.Lock()
|
c.m.Lock()
|
||||||
@ -100,6 +101,10 @@ type GraphicsContext interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Run(g GraphicsContext, width, height, scale int, title string, fps int) error {
|
func Run(g GraphicsContext, width, height, scale int, title string, fps int) error {
|
||||||
|
if currentRunContext != nil {
|
||||||
|
return errors.New("loop: The game is already running")
|
||||||
|
}
|
||||||
|
currentRunContext = &runContext{}
|
||||||
currentRunContext.startRunning()
|
currentRunContext.startRunning()
|
||||||
defer currentRunContext.endRunning()
|
defer currentRunContext.endRunning()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user