greenfork / nimraylib_now

The Ultimate Raylib gaming library wrapper for Nim
MIT License
151 stars 17 forks source link

Segfault loading a gltf #91

Closed suncore closed 1 year ago

suncore commented 1 year ago

Hi! I'm getting a segmentation fault when trying to load a .gltf model. I uploaded my little project here: https://drive.google.com/drive/folders/1YaZDWm_5ZVnaf78jPEhaDrI76ZazCMLL?usp=sharing

It is a modified version of one of the examples so this needs to live beside the examples so it can get files from the resources folder.

This is the output:

hch@srv:/a/proj/oc/src$ ./run
Hint: used config file '/home/hch/.choosenim/toolchains/nim-1.6.10/config/nim.cfg' [Conf]
Hint: used config file '/home/hch/.choosenim/toolchains/nim-1.6.10/config/config.nims' [Conf]
Hint: gc: orc; opt: speed; options: -d:release
9911 lines; 0.452s; 10.676MiB peakmem; proj: /a/proj/oc/src/main.nim; out: /a/proj/oc/src/main [SuccessX]
Hint: /a/proj/oc/src/main  [Exec]
INFO: Initializing raylib 4.2
INFO: Supported raylib modules:
INFO:     > rcore:..... loaded (mandatory)
INFO:     > rlgl:...... loaded (mandatory)
INFO:     > rshapes:... loaded (optional)
INFO:     > rtextures:. loaded (optional)
INFO:     > rtext:..... loaded (optional)
INFO:     > rmodels:... loaded (optional)
INFO:     > raudio:.... loaded (optional)
INFO: DISPLAY: Trying to enable MSAA x4
INFO: DISPLAY: Device initialized successfully
INFO:     > Display size: 3424 x 1353
INFO:     > Screen size:  800 x 450
INFO:     > Render size:  800 x 450
INFO:     > Viewport offsets: 0, 0
INFO: GLAD: OpenGL extensions loaded successfully
INFO: GL: Supported extensions count: 216
INFO: GL: OpenGL device information:
INFO:     > Vendor:   Mesa/X.org
INFO:     > Renderer: llvmpipe (LLVM 15.0.2, 256 bits)
INFO:     > Version:  4.5 (Core Profile) Mesa 22.2.1
INFO:     > GLSL:     4.50
INFO: GL: DXT compressed textures supported
INFO: GL: ETC2/EAC compressed textures supported
INFO: TEXTURE: [ID 1] Texture loaded successfully (1x1 | R8G8B8A8 | 1 mipmaps)
INFO: TEXTURE: [ID 1] Default texture loaded successfully
INFO: SHADER: [ID 1] Vertex shader compiled successfully
INFO: SHADER: [ID 2] Fragment shader compiled successfully
INFO: SHADER: [ID 3] Program shader loaded successfully
INFO: SHADER: [ID 3] Default shader loaded successfully
INFO: RLGL: Render batch vertex buffers loaded successfully in RAM (CPU)
INFO: RLGL: Render batch vertex buffers loaded successfully in VRAM (GPU)
INFO: RLGL: Default OpenGL state initialized successfully
INFO: TEXTURE: [ID 2] Texture loaded successfully (128x128 | GRAY_ALPHA | 1 mipmaps)
INFO: FONT: Default font loaded successfully (224 glyphs)
INFO: FILEIO: [ship.gltf] File loaded successfully
INFO: MODEL: [ship.gltf] Model basic data (glTF) loaded successfully
INFO:     > Meshes count: 1
INFO:     > Materials count: 1 (+1 default)
INFO: MODEL: [ship.gltf] Failed to load mesh/material buffers
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
Segmentation fault (core dumped)
Error: execution of an external program failed: '/a/proj/oc/src/main '
greenfork commented 1 year ago

Hi! I downloaded your project and I think I found the reason, Raylib only accepts a binary form of gltf models with a file extengion .glb. The wikipedia article links this page for possible converters, you will need to convert your gltf file to glb and then everything will work.

Also note that in main.nim the file path to a shader does not exist so everything is dark currently.

suncore commented 1 year ago

Thank you for your detailed and helpful response! :-)