g3n/engine

OBJ DecodeReader crashing without valid mtl

CannibalVox opened this issue · 3 comments

In #29, support was added for obj files with no valid material file- a plain gray material is loaded instead. In #101, a panic was discovered when no valid material file was available, and that was fixed. There is now a new panic:

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x18 pc=0x7ff737213039]

goroutine 1 [running, locked to thread]:
bufio.(*Reader).fill(0xc000387ab0)
        C:/Program Files/Go/src/bufio/bufio.go:101 +0xd9
bufio.(*Reader).ReadSlice(0xc000387ab0, 0x0)
        C:/Program Files/Go/src/bufio/bufio.go:360 +0x2f
bufio.(*Reader).collectFragments(0x7ff7371fbe8e, 0x0)
        C:/Program Files/Go/src/bufio/bufio.go:435 +0x74
bufio.(*Reader).ReadString(0x0, 0x2a)
        C:/Program Files/Go/src/bufio/bufio.go:483 +0x2b
github.com/g3n/engine/loader/obj.(*Decoder).parse(0xc0001860c0, {0x0, 0x0}, 0xc000387c48)
        C:/msys64/mingw64/pkg/mod/github.com/g3n/engine@v0.2.0/loader/obj/obj.go:407 +0x1be
github.com/g3n/engine/loader/obj.DecodeReader({0x20a37fa8a20, 0xc00009a0f0}, {0x0, 0x0})
        C:/msys64/mingw64/pkg/mod/github.com/g3n/engine@v0.2.0/loader/obj/obj.go:156 +0x2ad
main.(*HelloTriangleApplication).loadModel(0xc00018a000)
        C:/Users/Stephen/projects/VKng/examples/vulkan_tutorial/27_model_loading/main.go:1399 +0x6e
main.(*HelloTriangleApplication).initVulkan(0xc00018a000)
        C:/Users/Stephen/projects/VKng/examples/vulkan_tutorial/27_model_loading/main.go:271 +0x1c5
main.(*HelloTriangleApplication).Run(0xc00018a000)
        C:/Users/Stephen/projects/VKng/examples/vulkan_tutorial/27_model_loading/main.go:162 +0x53
main.main()
        C:/Users/Stephen/projects/VKng/examples/vulkan_tutorial/27_model_loading/main.go:2021 +0x2a
exit status 2

This is running in go 1.17- it's possible a change was made in a recent go version that causes buffer reading to panic with a nil reader where it didn't previously.

Hi Stephen!
I tested loading an obj file without a material file and it seemed to use the default material as expected, no panic.
(master branch, Go1.17.1)
Can you send me the offending obj file?

The obj file and also the code I used to repro. The obj file needs to be in the mesh folder for the example.

https://gist.github.com/CannibalVox/f59a6fc6c5a7af6cfa41fd0bbf6d9e82

Fixed by 549ee35. Thanks!