chunqian / go-raylib

go-raylib is a simple and easy-to-use library to enjoy videogames programming
zlib License
44 stars 3 forks source link

SIGSEGV LoadTextureFromImage #18

Closed hfabre closed 3 years ago

hfabre commented 3 years ago

Hi, using LoadTextureFromImage I got segmentation fault each time. Pretty short to reproduce:

package main

import (
    rl "github.com/chunqian/go-raylib/raylib"
    "runtime"
)

func init() {
    runtime.LockOSThread()
}

func main() {
    tileset := rl.LoadImage("./tileset.png")
    _ = rl.LoadTextureFromImage(tileset)
}

Results in:

INFO: FILEIO: [./tileset.png] File loaded successfully
INFO: IMAGE: [./tileset.png] Data loaded successfully (32x32)
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7fff3b703e6b]

runtime stack:
runtime.throw(0x41e1009, 0x2a)
    /usr/local/Cellar/go/1.13.4/libexec/src/runtime/panic.go:774 +0x72
runtime.sigpanic()
    /usr/local/Cellar/go/1.13.4/libexec/src/runtime/signal_unix.go:378 +0x47c

goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x40b95c0, 0xc000047de8, 0xc00000e400)
    /usr/local/Cellar/go/1.13.4/libexec/src/runtime/cgocall.go:128 +0x5b fp=0xc000047d98 sp=0xc000047d60 pc=0x40086cb
github.com/chunqian/go-raylib/raylib._Cfunc_LoadTextureFromImage(0x4809800, 0x2000000020, 0x400000001, 0x0, 0x0, 0x0)
    _cgo_gotypes.go:6208 +0x56 fp=0xc000047de8 sp=0xc000047d98 pc=0x408b0c6
github.com/chunqian/go-raylib/raylib.LoadTextureFromImage.func1(0x4809800, 0x2000000020, 0x400000001, 0x0, 0x0, 0x0)
    /Users/hfabre/go/src/github.com/chunqian/go-raylib/raylib/raylib.go:2085 +0xbb fp=0xc000047e58 sp=0xc000047de8 pc=0x408c1fb
github.com/chunqian/go-raylib/raylib.LoadTextureFromImage(0x4809800, 0x2000000020, 0x400000001, 0x0, 0x0, 0x0)
    /Users/hfabre/go/src/github.com/chunqian/go-raylib/raylib/raylib.go:2085 +0x92 fp=0xc000047f08 sp=0xc000047e58 pc=0x408c002
main.main()
    /Users/hfabre/local/perso/go/test/main.go:14 +0x62 fp=0xc000047f60 sp=0xc000047f08 pc=0x408cbc2
runtime.main()
    /usr/local/Cellar/go/1.13.4/libexec/src/runtime/proc.go:203 +0x21e fp=0xc000047fe0 sp=0xc000047f60 pc=0x4030fae
runtime.goexit()
    /usr/local/Cellar/go/1.13.4/libexec/src/runtime/asm_amd64.s:1357 +0x1 fp=0xc000047fe8 sp=0xc000047fe0 pc=0x4059551
exit status 2

Here is the image in case you need it:
tileset

chunqian commented 3 years ago

@hfabre

package main

import (
    rl "github.com/chunqian/go-raylib/raylib"
    "runtime"
)

func init() {
    runtime.LockOSThread()
}

func main() {
    screenWidth := int32(800)
    screenHeight := int32(450)
    rl.InitWindow(screenWidth, screenHeight, "raylib test")

    tileset := rl.LoadImage("./tileset.png")
    _ = rl.LoadTextureFromImage(tileset)
}

You need call rl.InitWindow()

chunqian commented 3 years ago

go-raylib used keep consistent with raylib c

hfabre commented 3 years ago

Oh sorry, I encountered this segmentation fault in a bigger project and I tried to reduce the code to make it easier to debug but it looks like there is no bug with this example. I'm going to take more time to debug my project to see if it's a bug or if I made a mistake

hfabre commented 3 years ago

Just gave a quick look at my project, and it looks like I made the same mistake, calling LoadTextureFromImage before initializing the window, sorry for the inconvenience