Skip to content

Commit

Permalink
Reorder shutdown functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sergystepanov committed Oct 20, 2023
1 parent 10c4cd9 commit 10507d9
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions pkg/worker/caged/libretro/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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")
}
Expand Down

0 comments on commit 10507d9

Please sign in to comment.