shareable: Bug fix: Double free

This commit is contained in:
Hajime Hoshi 2018-07-22 05:52:11 +09:00
parent 6687ffe8ba
commit 693116ffd6
2 changed files with 6 additions and 0 deletions

View File

@ -156,6 +156,9 @@ func (i *Image) forceShared() {
newI.replacePixels(pixels)
i.dispose(false)
*i = *newI
// TODO: This is a very tricky hack not to call Dispose twice for the same backend.
// Avoid such hack.
runtime.SetFinalizer(newI, nil)
}
func (i *Image) region() (x, y, width, height int) {

View File

@ -18,6 +18,7 @@ import (
"errors"
"image/color"
"os"
"runtime"
"testing"
"github.com/hajimehoshi/ebiten"
@ -183,4 +184,6 @@ func TestReshared(t *testing.T) {
}
}
}
runtime.GC()
}