On Tuesday, 21 March 2017 at 12:31:41 UTC, Robly18 wrote:

Two days of fix attempt laters, here I am. I tried reinstalling and recompiling SDL from source (since the version from apt-get was only 2.0.4 and the one Derelict uses seems to be 2.0.5), and it continues segfaulting at seemingly random places.

Mismatched versions wouldn't be causing a segfault out of the box. You'd be getting exceptions instead. The only way Derelict would be the cause of the segfault is if one of the function pointers is null or one of the function declarations has the wrong signature.

This isn't related to your problem, but beginning with DerelictSDL2 2.0, you can specify the version of SDL you'd like to target, like say 2.0.2:

import derelict.sdl2.sdl;
DerelictSDL2.load(SharedLibVersion(2, 0, 2));

With this, the loader will not throw any exceptions unless the library version is lower than the one requested. In that case, there is a potential to see segfaults. For example, you request at least 2.0.2, the user has 2.0.4, but the binding supports 2.0.5. The 2.0.5 functions will never be loaded, so the function pointers will be null.

If I ever get around to finishing up the documentation, it will recommend that you always specify the version you actually want and do not attempt to call any functions from later versions unless you have a good reason to do so, but always check for null first.


I have a function which fills the screen with black using SDL_FillRect... Then, this same function calls another helper function... Which segfaults, at SDL_FillRect. That is, the same function is both working and crashing, when given the exact same arguments, just in different contexts. And I have no idea why.

Looking over your code, I see you aren't doing any error checking. Validate all of your return values and call SDL_GetError when one of them shows an error (in SDL, that's either null or a number < 0, depending on the function). Add some asserts or debug code to check the state of the pointers you're passing to SDL functions. Given that the program works elsewhere, I wouldn't expect this to show the issue, but it's still something you should be doing anyway.


I'll put a link to the repo. It is a slightly more updated version than the one I've been trying to compile, but it segfaults anyway. I'm continuing to develop just fine on Windows, but Derelict on Ubuntu has proven to be a nightmare.

Derelict has worked on Ubuntu for years. It doesn't do anything special there that it doesn't do on Windows. I'm not able to check it at the moment, but I have an Ubuntu laptop I'll try your code on when I get the chance (if you don't resolve the issue first).


TL;DR: Same code runs on Windows but not Ubuntu, tried to update and recompile all I could, segmentation faults on seemingly random places.

http://www.github.com/robly18/sdltest/


Reply via email to