ui: Panic if Layout returns non-positive numbers

This commit is contained in:
Hajime Hoshi 2019-12-23 04:43:04 +09:00
parent 049aa552d4
commit 1d9c00688c
2 changed files with 6 additions and 1 deletions

4
run.go
View File

@ -36,7 +36,9 @@ type Game interface {
// //
// The screen scale is automatically adjusted to fit the outside. // 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 // 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. // adjusted with the given outside size.

View File

@ -147,6 +147,9 @@ func (c *uiContext) Layout(outsideWidth, outsideHeight float64) {
func (c *uiContext) updateOffscreen() { func (c *uiContext) updateOffscreen() {
sw, sh := c.game.Layout(int(c.outsideWidth), int(c.outsideHeight)) 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 c.offscreen != nil && !c.outsideSizeUpdated {
if w, h := c.offscreen.Size(); w == sw && h == sh { if w, h := c.offscreen.Size(); w == sw && h == sh {