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

nil crash #101

Open
objarni opened this issue Jan 26, 2021 · 1 comment
Open

nil crash #101

objarni opened this issue Jan 26, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@objarni
Copy link
Contributor

objarni commented Jan 26, 2021

Describe the bug
tilepix crashes with message "cannot create sprite from nil tileset" on simple example program.

To Reproduce

  1. Clone https://github.com/objarni/rescue-on-fractal-bun
  2. Modify the replace directive in go.mod so that it points to latest version of tilepix on your machine
    (I tried running the latest version instead of latest release since the latest release crashed, but with a different error)
  3. go run examples/tiled_test/main.go
  4. Crash with output:
ERRO[0000] TileLayer.Batch: layers' tileset is nil       error="cannot create sprite from nil tileset"
ERRO[0000] TileLayer.Draw: could not get batch           error="cannot create sprite from nil tileset"
ERRO[0000] Map.DrawAll: could not draw layer             error="cannot create sprite from nil tileset"
panic: cannot create sprite from nil tileset

Expected behavior
tiled_test/main.go is a copy-paste of the front page example program, but with GhostForest.tmx instead.

A guess is that something is assumed about how .tmx files are structured that I am missing (I'm a new user to Tiled aswell as tilepix).

Environment (please complete the following information):

GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/olof/.cache/go-build"
GOENV="/home/olof/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/olof/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/olof/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/snap/go/current"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/snap/go/current/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/olof/repos/github/rescue-on-fractal-bun/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build719279645=/tmp/go-build -gno-record-gcc-switches"

Additional context

Thanks for a neat little library! I wouldn't mind pair-programming with you to help fix this issue :)

@objarni objarni added the bug Something isn't working label Jan 26, 2021
@objarni
Copy link
Contributor Author

objarni commented Jan 27, 2021

OK, I think I got a workaround:

  1. In Tiled, make sure any empty layer (meaning no tile has been "painted" on it in Tiled) exists. For example by removing such layers.
  2. Save the .tmx with only layers that are non-empty

Suggested fix, one of:
a) when loading a .tmx file, either do not create layers that have no tile set (all are nil) so that this crash is prevented
b) make rendering code not assume sprites exist for a layer (just skip rendering it if the sprite is null)
c) error-out if the loaded .tmx file contains empty levels, e.g something on the style of
"Error: .tmx files with layers without any tiles are not supported"

What do you think @bcvery1 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant