Dgame RC #1

Mike Parker via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Thu Apr 2 21:55:41 PDT 2015


On Thursday, 2 April 2015 at 09:38:05 UTC, Namespace wrote:

>
> Dgame is based on SDL 2.0.3 (as described in the installation 
> tutorial), but tries to "wrap" any function call which is 
> introduced after SDL 2.0.0:
> ----
> static if (SDL_VERSION_ATLEAST(2, 0, 2))
> ----
> so that Dgame should be usable with any SDL2.x version.
>
> I will investigate which function is calling SDL_HasAVX.

None of that matters. This has nothing to do with what Dgame is 
calling, but what Derelict is actually trying to load. SDL_HasAVX 
was added to the API in 2.0.2 so does not exist in previous 
versions of SDL, therefore an exception will be thrown when 
Derelict tries to load older versions and that function is 
missing.

> Dgame will load DerelictSDL2 as usual and then it will check if 
> the supported version is below 2.0.2. If so, DerelictSDL2 will 
> be reloaded with SharedLibVersion(MAX_SUPPORTED_VERSION)).

> That should that work, right?

No, it won't. By default, Derelict attempts to load functions 
from the 2.0.2 API (which includes 2.0.3, since the API did not 
change). That means anything below 2.0.2 will *always* fail to 
load because they are missing the functions added to the API in 
2.0.2.

The right way to do this is to use the selective loading 
mechanism to disable exceptions for certain functions. With the 
1.9.x versions of DerelictSDL2, you no longer have to implement 
that manually. As I wrote above, you can do this:

DerelictSDL2.load(SharedLibVersion(2,0,0));

With that, you can load any version of SDL2 available on the 
system, from 2.0.0 on up. It uses selective loading internally. 
For example, 2.0.0 will load even though it is missing SDL_HasAVX 
and several other functions added in 2.0.1 and 2.0.2. But you 
should only do this if you are absolutely sure that you are not 
calling any functions that were not present in 2.0.0. For 
example, the SDL_GetPrefPath/SDL_GetBasePath functions were added 
in 2.0.1. If you require those and need nothing from 2.0.2, then 
you should do this:

DerelictSDL2.load(SharedLibVersion(2,0,1));

Now, 2.0.0 will fail to load, but 2.0.1 and higher will succeed. 
You can look at the functions allowSDL_2_0_0 and allowSDL_2_0_1 
in sdl.d [1] to see exactly which functions were added in 2.0.1 
and 2.0.2 so that you can determine if you require any of them. I 
also encourage you to go and do a diff of the SDL headers for 
each release to see things other than functions, like new 
constants, that were added in each release (and to protect 
against the possibility that I've made a mistake somewhere). That 
won't affect whether or not Derleict loads, but a new constant 
added in SDL 2.0.2 won't work with a function that existed in 
2.0.0, for example.


More information about the Digitalmars-d-announce mailing list