go-sdl2
go-sdl2 copied to clipboard
Crash on Windows calling Texture.Destroy()
Installed today from latest github head, my code does this:
texture, err := renderer.CreateTextureFromSurface(surface)
if err != nil {
panic(err)
}
defer texture.Destroy()
surface.Free()
dst := sdl.Rect{int32(X), int32(Y), int32(W), int32(H)}
renderer.Copy(texture, nil, &dst)
Which throws
signal arrived during external code execution
The stack traces is as follows:
github.com/veandco/go-sdl2/sdl._Cfunc_GoSetError(0x0)
_cgo_gotypes.go:1646 +0x33
github.com/veandco/go-sdl2/sdl.SetError(0x0, 0x0)
/home/nrich/go/src/github.com/veandco/go-sdl2/sdl/error.go:52 +0x59
github.com/veandco/go-sdl2/sdl.(*Texture).Destroy(0x33778fc0, 0x33778fc0, 0x0)
/home/nrich/go/src/github.com/veandco/go-sdl2/sdl/render.go:600 +0x6a
Changing go-sdl2/sdl/error.go:52 from:
C.GoSetError(nil)
to:
C.GoSetError(C.CString(""))
seems to stop the crash.
Hi @nrich, I'll look into this when I get on my Windows computer!
I tried to reproduce it on my Windows computer but I can't seem to do it. If possible, could you please add a minimal example that would reproduce the crash? Some info on your C/C++/Go compilers, Windows, and SDL2 would help. In the meantime, I applied your fix to the master branch :)
Thanks!
Hi @veeableful, I'll put together a minimal example when I get back to my dev PC. A complication to trigger this bug may be the fact I'm cross compiling from Linux to Windows.
In the meantime, here are my env details:
Windows: 10 SDL: SDL2-2.0.5 go version go1.10.1 linux/amd64 CC: i686-w64-mingw32-gcc Linux: Ubuntu 16.04.4
I'm building my app with the following command:
env CGO_CFLAGS="-I$(pwd)/win32/SDL2-2.0.5/i686-w64-mingw32/include/ -I$(pwd)/win32/libjpeg/32/include/" CGO_LDFLAGS="-L$(pwd)/win32/SDL2-2.0.5/i686-w64-mingw32/bin/ -L $(pwd)/win32/libjpeg/32/lib -ljpeg" CC=i686-w64-mingw32-gcc CGO_ENABLED=1 GOOS=windows GOARCH=386 go build
Hi @veeableful,
Here is a minimal example that triggers the bug:
package main
import (
"github.com/veandco/go-sdl2/sdl"
)
func applyScreenUpdate(renderer *sdl.Renderer, surface *sdl.Surface, W,H int32) {
texture, err := renderer.CreateTextureFromSurface(surface)
if err != nil {
panic(err)
}
defer texture.Destroy()
surface.Free()
dst := sdl.Rect{int32(0), int32(0), W, H}
renderer.Copy(texture, nil, &dst)
}
func main() {
var err error
var window *sdl.Window
var renderer *sdl.Renderer
if err = sdl.Init(sdl.INIT_EVERYTHING); err != nil {
panic(err)
}
defer sdl.Quit()
window, err = sdl.CreateWindow("test", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, int32(800), int32(600), sdl.WINDOW_RESIZABLE)
if err != nil {
panic(err)
}
defer window.Destroy()
renderer, err = sdl.CreateRenderer(window, -1, sdl.RENDERER_SOFTWARE)
if err != nil {
panic(err)
}
s, err := sdl.CreateRGBSurface(0, int32(8), int32(8), 32, 0, 0, 0, 0)
if err != nil {
panic(err)
}
pix := s.Pixels()
for y := 0; y < 8; y++ {
for x := 0; x < 8; x++ {
i := y*8+x
pix[4*i] = 255
pix[4*i+1] = 255
pix[4*i+2] = 255
pix[4*i+3] = 1.0
}
}
applyScreenUpdate(renderer, s, 8, 8)
sdl.Delay(2000)
}
Same build env as above.
Exception thrown:
Exception 0xc0000005 0x0 0x0 0x6c7c0480
PC=0x6c7c0480
signal arrived during external code execution
github.com/veandco/go-sdl2/sdl._Cfunc_GoSetError(0x0)
_cgo_gotypes.go:1643 +0x33
github.com/veandco/go-sdl2/sdl.SetError(0x0, 0x0)
/home/nrich/go/src/github.com/veandco/go-sdl2/sdl/error.go:52 +0x59
github.com/veandco/go-sdl2/sdl.(*Texture).Destroy(0x33563d00, 0x0, 0x0)
/home/nrich/go/src/github.com/veandco/go-sdl2/sdl/render.go:600 +0x6a
main.applyScreenUpdate(0x335639c0, 0x33563b58, 0x8, 0x8)
/home/nrich/testcase/main.go:19 +0xa8
main.main()
/home/nrich/testcase/main.go:59 +0x20a
eax 0x7efb98
ebx 0x7efb98
ecx 0x0
edx 0x200
edi 0x7efda8
esi 0x0
ebp 0x7efac0
esp 0x7efa28
eip 0x6c7c0480
eflags 0x10246
cs 0x23
fs 0x53
gs 0x2b