run: Bug fix: The screen can be nil in the initial state

Fixes #1039
This commit is contained in:
Hajime Hoshi 2019-12-29 23:14:57 +09:00
parent 17dc972b7a
commit 662a22461d

View File

@ -229,14 +229,23 @@ func (c *uiContext) offsets() (float64, float64) {
}
func (c *uiContext) Update(afterFrameUpdate func()) error {
updateCount := clock.Update(MaxTPS())
// TODO: If updateCount is 0 and vsync is disabled, swapping buffers can be skipped.
if err := buffered.BeginFrame(); err != nil {
return err
}
if err := c.update(afterFrameUpdate); err != nil {
return err
}
if err := buffered.EndFrame(); err != nil {
return err
}
return nil
}
func (c *uiContext) update(afterFrameUpdate func()) error {
updateCount := clock.Update(MaxTPS())
for i := 0; i < updateCount; i++ {
c.updateOffscreen()
@ -255,6 +264,11 @@ func (c *uiContext) Update(afterFrameUpdate func()) error {
afterFrameUpdate()
}
// c.screen might be nil when updateCount is 0 in the initial state (#1039).
if c.screen == nil {
return nil
}
// This clear is needed for fullscreen mode or some mobile platforms (#622).
c.screen.Clear()
@ -285,10 +299,6 @@ func (c *uiContext) Update(afterFrameUpdate func()) error {
op.Filter = FilterLinear
}
_ = c.screen.DrawImage(c.offscreen, op)
if err := buffered.EndFrame(); err != nil {
return err
}
return nil
}