From 857bc1ed519ed2c78955d3e4c055a666f968893e Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 29 May 2016 02:51:34 +0900 Subject: [PATCH] loop: Prevent re-entering to Run --- internal/loop/run.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/loop/run.go b/internal/loop/run.go index 2863ec26a..42bb14056 100644 --- a/internal/loop/run.go +++ b/internal/loop/run.go @@ -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()