From ce24640da89b80762e20ce6845f5deeba5a04d80 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 20 Dec 2020 21:10:47 +0900 Subject: [PATCH] ebiten: Ensure that Layout is called before Update in the first frame --- run.go | 2 ++ uicontext.go | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/run.go b/run.go index 355108aac..1505d164c 100644 --- a/run.go +++ b/run.go @@ -50,6 +50,8 @@ type Game interface { // // Layout is called almost every frame. // + // It is ensured that Layout is invoked before Update is called in the first frame. + // // If Layout returns non-positive numbers, the caller can panic. // // You can return a fixed screen size if you don't care, or you can also return a calculated screen size diff --git a/uicontext.go b/uicontext.go index de87e02fa..300c45e66 100644 --- a/uicontext.go +++ b/uicontext.go @@ -155,6 +155,8 @@ func (c *uiContext) Update() error { } func (c *uiContext) update() error { + c.updateOffscreen() + updateCount := clock.Update(MaxTPS()) // Ensure that Update is called once before Draw so that Update can be used for initialization. @@ -174,8 +176,6 @@ func (c *uiContext) update() error { uiDriver().ResetForFrame() } - c.updateOffscreen() - if updateCount > 0 { if IsScreenClearedEveryFrame() { c.offscreen.Clear()