Skip to content

Commit

Permalink
Fix image.Image leak
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth authored and andydotxyz committed May 29, 2023
1 parent ccc2f93 commit 67d5cba
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion internal/painter/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ func GetAspect(img *canvas.Image) float32 {
aspect = aspects[img.Resource.Name()]
} else if img.File != "" {
aspect = aspects[img.File]
} else if img.Image != nil {
// HOTFIX until Fyne 2.4 proper fix:
// we are not storing the aspect ratio in the map for the image.Image case
size := img.Image.Bounds().Size()
return float32(size.X) / float32(size.Y)
}

if aspect == 0 {
Expand Down Expand Up @@ -132,7 +137,9 @@ func paintImage(img *canvas.Image, width, height int, wantOrigSize bool, wantOri
case img.Image != nil:
origSize := img.Image.Bounds().Size()
origW, origH = origSize.X, origSize.Y
if checkSize(origSize.X, origSize.Y) {
// HOTFIX until Fyne 2.4: don't store aspect ratio in map, as checkSize(x, y) does.
// Doing so leaks a reference to the image.Image data
if !wantOrigSize || (wantOrigW == origW && wantOrigH == origH) {
dst = scaleImage(img.Image, width, height, img.ScaleMode)
}
default:
Expand Down

0 comments on commit 67d5cba

Please sign in to comment.