fixed app freezing on exit by saving project stuff in background on exit
This commit is contained in:
@@ -80,47 +80,45 @@ func main() {
|
||||
heightmapPath := filepath.Join(appConfigDir, "heightmap.png")
|
||||
bumpmapPath := filepath.Join(appConfigDir, "bumpmap.png")
|
||||
|
||||
// Save settings and images on window close
|
||||
w.SetOnClosed(func() {
|
||||
// Hide the window immediately on close, then save in the background.
|
||||
closing := false
|
||||
w.SetCloseIntercept(func() {
|
||||
if closing {
|
||||
return
|
||||
}
|
||||
closing = true
|
||||
|
||||
canvasSnapshot := canvasImg.Image
|
||||
heightmapSnapshot := heightmapImg.Image
|
||||
bumpmapSnapshot := bumpmapImg.Image
|
||||
|
||||
w.Hide()
|
||||
go func() {
|
||||
saveImage := func(path string, img image.Image, label string) {
|
||||
if img == nil {
|
||||
return
|
||||
}
|
||||
file, err := os.Create(path)
|
||||
if err != nil {
|
||||
log.Println("Failed to create "+label+" file:", err)
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
if err := png.Encode(file, img); err != nil {
|
||||
log.Println("Failed to encode "+label+" image:", err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := settings.Save(); err != nil {
|
||||
log.Println("Error saving settings:", err)
|
||||
}
|
||||
|
||||
if canvasImg.Image != nil {
|
||||
canvasFile, err := os.Create(canvasPath)
|
||||
if err != nil {
|
||||
log.Println("Failed to create canvas file:", err)
|
||||
} else {
|
||||
defer canvasFile.Close()
|
||||
if err := png.Encode(canvasFile, canvasImg.Image); err != nil {
|
||||
log.Println("Failed to encode canvas image:", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if heightmapImg.Image != nil {
|
||||
heightmapFile, err := os.Create(heightmapPath)
|
||||
if err != nil {
|
||||
log.Println("Failed to create heightmap file:", err)
|
||||
} else {
|
||||
defer heightmapFile.Close()
|
||||
if err := png.Encode(heightmapFile, heightmapImg.Image); err != nil {
|
||||
log.Println("Failed to encode heightmap image:", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if bumpmapImg.Image != nil {
|
||||
bumpmapFile, err := os.Create(bumpmapPath)
|
||||
if err != nil {
|
||||
log.Println("Failed to create bumpmap file:", err)
|
||||
} else {
|
||||
defer bumpmapFile.Close()
|
||||
if err := png.Encode(bumpmapFile, bumpmapImg.Image); err != nil {
|
||||
log.Println("Failed to encode bumpmap image:", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
saveImage(canvasPath, canvasSnapshot, "canvas")
|
||||
saveImage(heightmapPath, heightmapSnapshot, "heightmap")
|
||||
saveImage(bumpmapPath, bumpmapSnapshot, "bumpmap")
|
||||
fyne.Do(func() {
|
||||
a.Quit()
|
||||
})
|
||||
}()
|
||||
})
|
||||
|
||||
// Load previously saved images
|
||||
|
||||
Reference in New Issue
Block a user