Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on Windows calling Texture.Destroy() #340

Open
nrich opened this issue Jul 7, 2018 · 5 comments
Open

Crash on Windows calling Texture.Destroy() #340

nrich opened this issue Jul 7, 2018 · 5 comments
Labels
bug This issue describes a bug in the project

Comments

@nrich
Copy link

nrich commented Jul 7, 2018

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.

@veeableful
Copy link
Contributor

Hi @nrich, I'll look into this when I get on my Windows computer!

veeableful added a commit that referenced this issue Jul 9, 2018
Apparently caused by sdl.SetError(nil) but it doesn't
always happen.

See #340

Signed-off-by: Lilis Iskandar <[email protected]>
@veeableful
Copy link
Contributor

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!

@veeableful veeableful added the bug This issue describes a bug in the project label Jul 9, 2018
@nrich
Copy link
Author

nrich commented Jul 9, 2018

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

@nrich
Copy link
Author

nrich commented Jul 10, 2018

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.

@nrich
Copy link
Author

nrich commented Jul 10, 2018

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

@veeableful veeableful added the solved? This issue might have been solved but not tested label Jul 19, 2018
@veeableful veeableful removed the solved? This issue might have been solved but not tested label Aug 21, 2019
neputevshina pushed a commit to neputevshina/go-sdl2 that referenced this issue Nov 13, 2024
Apparently caused by sdl.SetError(nil) but it doesn't
always happen.

See veandco#340

Signed-off-by: Lilis Iskandar <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue describes a bug in the project
Projects
None yet
Development

No branches or pull requests

2 participants