mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 13:07:26 +01:00
loop: Prevent re-entering to Run
This commit is contained in:
parent
a329f7939d
commit
857bc1ed51
@ -15,6 +15,7 @@
|
||||
package loop
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@ -40,7 +41,7 @@ type runContext struct {
|
||||
m sync.RWMutex
|
||||
}
|
||||
|
||||
var currentRunContext runContext
|
||||
var currentRunContext *runContext
|
||||
|
||||
func (c *runContext) startRunning() {
|
||||
c.m.Lock()
|
||||
@ -100,6 +101,10 @@ type GraphicsContext interface {
|
||||
}
|
||||
|
||||
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()
|
||||
defer currentRunContext.endRunning()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user