Fix closing already closed channel on exit

This commit is contained in:
2025-04-16 12:22:08 +02:00
parent 9d60d5e9cd
commit 62a6bb2926
2 changed files with 83 additions and 28 deletions

View File

@ -410,7 +410,13 @@ func (g *Game) Cleanup() {
rl.UnloadMusicStream(g.AssetManager.Music)
}
close(g.quitChan)
// Only close the channel if it hasn't been closed yet
select {
case <-g.quitChan:
// Channel already closed, do nothing
default:
close(g.quitChan)
}
})
}
@ -491,7 +497,8 @@ func (g *Game) DrawMenu() {
}
func (g *Game) Shutdown() {
close(g.quitChan)
// Use the cleanup method which has channel-closing safety
g.Cleanup()
}
func (g *Game) HandleServerMessages(messages []*pb.ChatMessage) {