From 10507d9c53599367dd375c5177c10aef93e7e373 Mon Sep 17 00:00:00 2001 From: Sergey Stepanov Date: Sat, 21 Oct 2023 00:07:10 +0300 Subject: [PATCH] Reorder shutdown functions --- pkg/worker/caged/libretro/frontend.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/pkg/worker/caged/libretro/frontend.go b/pkg/worker/caged/libretro/frontend.go index 80392dedd..462a10d26 100644 --- a/pkg/worker/caged/libretro/frontend.go +++ b/pkg/worker/caged/libretro/frontend.go @@ -217,11 +217,20 @@ func (f *Frontend) SetOnAV(fn func()) { f.nano.OnSystemAvInfo = fn } func (f *Frontend) Start() { f.log.Debug().Msgf("frontend start") + f.mui.Lock() f.done = make(chan struct{}) f.nano.LastFrameTime = time.Now().UnixNano() - f.mui.Lock() - defer f.Shutdown() + defer func() { + // Save game on quit if it was saved before (shared or click-saved). + if f.SaveOnClose && f.HasSave() { + f.log.Debug().Msg("save on quit") + if err := f.Save(); err != nil { + f.log.Error().Err(err).Msg("save on quit failed") + } + } + f.Shutdown() + }() defer f.mui.Unlock() if f.HasSave() { @@ -306,17 +315,11 @@ func (f *Frontend) ViewportCalc() (nw int, nh int) { func (f *Frontend) Close() { f.log.Debug().Msgf("frontend close") + close(f.done) f.mui.Lock() defer f.mui.Unlock() - // Save game on quit if it was saved before (shared or click-saved). - if f.SaveOnClose && f.HasSave() { - f.log.Debug().Msg("Save on quit") - if err := f.Save(); err != nil { - f.log.Error().Err(err).Msg("save on quit failed") - } - } f.nano.Close() f.log.Debug().Msgf("frontend closed") }