I am currently trying out DerelictSDL2 (a binding to the SDL2 library for D) and I've written a code that successfully loads a JPG image and displays it in a window. That is, when it's compiled with dmd. When I try with gdc (and no code modification), it does compile but it won't load the image at runtime.
I believe I did things right :
and somewhere after that
this.data = IMG_LoadTexture(Window.renderer, name.ptr)
Window.renderer is (obviously) the
name.ptr is a
char* pointing to the name of the image to load. But when compiling with gdc,
IMG_LoadTexture both return
null, while with dmd they return a pointer to the newly created texture...
Did I forget something else (after all, with dmd it worked even without
IMG_Init) ? Does Derelict only works with dmd (even if it's only interfacing to C functions) ?
dmd : 2.065
gdc : 4.9.1
Turns out the problem is completely different.
IMG_LoadTexture takes a pointer to data for its second argument but
name.ptr seems to only work with dmd. However If I try with a hard-coded argument like this :
it works with both dmd and gdc.
there is no guarantee that D string will be 0-terminated. it just happens by chance with dmd. the correct way is to use toStringz() function from std.string module.
p.s. please note that string literals are 0-terminated, that's why hardcoded arguments works.