DEV Community

Calin Baenen
Calin Baenen

Posted on

Why do I keep getting this weird error when trying to load an image?

So I'm trying to make a game in GoLang using Raylib Go (Go bindings of a C library with the same name).

I'm using a temporary variable to test if I can load a texture (I'm only gonna show the one line, as that's the only thing that makes the program crash):

var _ rl.Texture2D = rl.LoadTexture("./rsrc/textures/logo.png");
Enter fullscreen mode Exit fullscreen mode

Yes, the path "./rsrc/textures/logo.png" exists (relative to the executable's default directory).
After putting that in, I ran two commands in Command Prompt (Windows 10)

C:\Users\Administrator\Desktop\Projects\Go\games\RuntDeale>go build ./rsrc/code
C:\Users\Administrator\Desktop\Projects\Go\games\RuntDeale>code
Enter fullscreen mode Exit fullscreen mode



After running that last command, no window appeared, and the program had seemed to have ended.
But I got this lovely jumble of text printed to me:

INFO: FILEIO: [./rsrc/textures/logo.png] File loaded successfully
INFO: IMAGE: [./rsrc/textures/logo.png] Data loaded successfully (76x17)
Exception 0xc0000005 0x8 0x0 0x0
PC=0x0
signal arrived during external code execution

github.com/gen2brain/raylib-go/raylib._Cfunc_LoadTexture(0x14d740b1bb0, 0x0, 0x0, 0xc000000000)
        _cgo_gotypes.go:4223 +0x54
github.com/gen2brain/raylib-go/raylib.LoadTexture(0x972c59, 0x18, 0x0, 0x0, 0x14d00000000)
        C:/Users/Administrator/go/pkg/mod/github.com/gen2brain/raylib-go@v0.0.0-20210227124741-9d258bad6516/raylib/textures.go:69 +0x95
main.main()
        C:/Users/Administrator/Desktop/Projects/Go/games/RuntDeale/rsrc/code/main.go:28 +0xa5
rax     0x700000001
rbx     0x2a527ffaf0
rcx     0xde1
rdi     0x11
rsi     0x4c
rbp     0x7
rsp     0x2a527ff978
r8      0x11
r9      0x7
r10     0x0
r11     0x246
r12     0x1
r13     0x978368
r14     0x37
r15     0xffffffffffffffff
rip     0x0
rflags  0x10246
cs      0x33
fs      0x53
gs      0x2b
Enter fullscreen mode Exit fullscreen mode

It says the file loaded successfully, but then it has some kind of error, and doesn't really make any sense.

What does this mean, and how can I fix it?




Thanks!
Cheers!

Discussion (3)

Collapse
cariehl profile image
Cooper Riehl

I've never used raylib, but my initial guess is that you're either missing a step, or doing something out-of-order from what the library expects.

It's hard to diagnose your problem based on a single line of code. Can you create a new program that only loads the texture, then post the full source code? That will make it easier to trace through the steps and figure out if you're missing something, doing something wrong, etc.

Collapse
baenencalin profile image
Calin Baenen Author

Raylib is similar to OpenGL (I think it even uses OpenGL BTS).

Here is a minimal example:

package main;

import "github.com/gen2brain/raylib-go/raylib";







// Main function (program entrypoint).
func main() {
  var tex rl.Texture2D = rl.LoadTexture("test.jpg");

  rl.InitWindow(500, 500, "Raylib test.");
  for !rl.WindowShouldClose() {
    rl.ClearBackground(rl.Black);
    rl.DrawTexture(tex, 0, 0, rl.Blank);
  }
}
Enter fullscreen mode Exit fullscreen mode

This is the application in the file system. Yes,  raw `test.jpg` endraw  exists.
And I get a pretty similar result to the last (except jpg isn't a supported format, for some reason (not like I use jpg, but I still care about them)).

INFO: FILEIO: [test.jpg] File loaded successfully
WARNING: IMAGE: File format not supported
WARNING: IMAGE: [test.jpg] Failed to load data
INFO: Initializing raylib 3.8-dev
INFO: DISPLAY: Device initialized successfully
INFO:     > Display size: 1920 x 1080
INFO:     > Render size:  500 x 500
INFO:     > Screen size:  500 x 500
INFO:     > Viewport offsets: 0, 0
INFO: GLAD: OpenGL extensions loaded successfully
INFO: GL: Supported extensions count: 239
INFO: GL: OpenGL device information:
INFO:     > Vendor:   Intel
INFO:     > Renderer: Intel(R) UHD Graphics 630
INFO:     > Version:  3.3.0 - Build 27.20.100.8853
INFO:     > GLSL:     3.30 - Build 27.20.100.8853
INFO: GL: DXT compressed textures supported
INFO: GL: ETC2/EAC compressed textures supported
INFO: TEXTURE: [ID 1] Texture loaded successfully (1x1 - 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 - 1 mipmaps)
INFO: FONT: Default font loaded successfully
Enter fullscreen mode Exit fullscreen mode
Collapse
baenencalin profile image
Calin Baenen Author

NOTE: I tried adding rl.UnloadTexture(tex) after the window initialization, and I tried putting it after the for loop. When I do this, the window does appear this time, but it instantly closes, and provides the same (or similar) error (I didn't look too carefully, since they seem the same).
With that said, I can tell it's an issue with rl.LoadTexture(string), and not me, or rl.UnloadTexture(rl.Texture2D).