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