Derelict SDL segfaulting on ubuntu?
Mike Parker via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Mar 21 20:44:17 PDT 2017
On Tuesday, 21 March 2017 at 19:26:47 UTC, Robly18 wrote:
>
> Oh! Right, I forgot to mention that, my bad. The earliest
> errors were, as you said, mismatched version exceptions.
> However, to fix them, what I did was, at first, do the 2,0,2
> version thing you said. Later, however, I decided to compile
> SDL 2.0.5 myself, and I believe the exceptions stopped
> occurring. The segfaults, however, did not.
When you compiled SDL 2.0.5, did you also install it? The
Derelict loader will load the shared library from the system
path, so if you didn't redirect the symlink on the system path
from the old library to your newer one, then the Derelict would
still be loading the old one. And then if you're calling any
2.0.5 functions, they wouldn't be loaded so you'd see the
segfault.
>
> You said something about null function pointers... Is this
> something I should be checking for?
Not generally, no. However, if you are specifying one version as
the minimum you require, then using functions from a later
version, then yes. Example:
You call DerelictSDL2.load(SharedLibVersion(2,0,2)). Then later
in your code, you have a call to SDL_GetWindowBorderSize. This is
a function that was added in SDL 2.0.5. If you run your program
on a system that has SDL 2.0.5, then no problem. But you
requested 2.0.2 as a minimum, so your program will still load
successfully with no exceptions if the user has SDL 2.0.2, 2.0.3,
or 2.0.4. But in all three of those cases,
SDL_GetWindowBorderSize will never be loaded, so it will be null
when you call it and you will get a segfault.
If you truly want to use that function only if it's available,
then you need to check for null first (or call SDL_GetVersion to
see which version si actually loaded). It's like checking if an
extension is loaded in OpenGL. But that kind of usage is rare
with SDL, and *I strongly recommend against it*. Generally if you
need functions from a specific version, then that should be the
minimum version you request.
DerelictSDL2 2.1.x will load SDL 2.0.5 by default when no
SharedLibVersion is specified. So if you need any function from
2.0.5, then just use the default. However, that means the user
will need 2.0.5 on their system and anything lower will cause an
exception to be thrown during load.
> I know when I did the version downgrade I got dub complaining
> about some undefined functions, but should I be on the lookout
> for more?
That's the compiler complaining, not dub. DerelictSDL2 2.0.x (and
1.9.x, since that was 2.0 beta) supports up to SDL 2.0.4. No
functions from SDL 2.0.5 are declared anywhere.
So given what I know so far, my guess is you're using functions
from 2.0.5 with a 2.0.4 version of the library. You can call
SDL_GetVersion [1] to verify. In that case, you need to use
DerelictSDL2 2.1.x and do no use SharedLibVersion -- just let it
load the default.
http://wiki.libsdl.org/SDL_GetVersion?highlight=%28%5CbCategoryAPI%5Cb%29%7C%28SDLFunctionTemplate%29
More information about the Digitalmars-d-learn
mailing list