From 1d9c00688c188e1036260b90ced7e9dfe74d843b Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 23 Dec 2019 04:43:04 +0900 Subject: [PATCH] ui: Panic if Layout returns non-positive numbers --- run.go | 4 +++- uicontext.go | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/run.go b/run.go index 414d2edd0..f320147d8 100644 --- a/run.go +++ b/run.go @@ -36,7 +36,9 @@ type Game interface { // // The screen scale is automatically adjusted to fit the outside. // - // Layout is called at an initialization and whenever the outside size is changed. + // Layout is called almost every 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 // adjusted with the given outside size. diff --git a/uicontext.go b/uicontext.go index 7f050e507..0c319c8dc 100644 --- a/uicontext.go +++ b/uicontext.go @@ -147,6 +147,9 @@ func (c *uiContext) Layout(outsideWidth, outsideHeight float64) { func (c *uiContext) updateOffscreen() { sw, sh := c.game.Layout(int(c.outsideWidth), int(c.outsideHeight)) + if sw <= 0 || sh <= 0 { + panic("ebiten: Layout must return positive numbers") + } if c.offscreen != nil && !c.outsideSizeUpdated { if w, h := c.offscreen.Size(); w == sw && h == sh {