From 55c2232e08d830e865dd46ad81c21d1231796a17 Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Wed, 23 Oct 2024 23:54:48 +0100 Subject: [PATCH] Fix a SIGSEGV --- internal/ordoor/ordoor.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/ordoor/ordoor.go b/internal/ordoor/ordoor.go index acff7df..8e53537 100644 --- a/internal/ordoor/ordoor.go +++ b/internal/ordoor/ordoor.go @@ -7,6 +7,7 @@ package ordoor import ( "fmt" "log" + "sync" "time" "github.com/hajimehoshi/ebiten/v2" @@ -28,7 +29,8 @@ type Ordoor struct { win *ui.Window // Relevant to interface state - flow *flow.Flow + flow *flow.Flow + flowOnce sync.Once // FIXME: should be put inside flow // If this is set, we display it instead of flow @@ -178,6 +180,7 @@ func (o *Ordoor) Update(screenX, screenY int) error { } func (o *Ordoor) Draw(screen *ebiten.Image) error { + if pic := o.pic; pic != nil { // Scale the picture to the screen and draw it scaleX := float64(screen.Bounds().Dx()) / float64(pic.Bounds().Dx()) @@ -190,7 +193,11 @@ func (o *Ordoor) Draw(screen *ebiten.Image) error { return nil } - return o.flow.Draw(screen) + if o.flow != nil { + return o.flow.Draw(screen) + } + + return nil // Draw() may be called before Update() } func (o *Ordoor) Cursor() (*ebiten.Image, *ebiten.DrawImageOptions, error) {