3

I am trying to use Derelict and D to write a simple graphics test program.

When I try to do nearly anything with SDL it will seg-fault. Here is the code that is having issues:

import std.stdio;   
import derelict.opengl3.gl3; 
import derelict.sdl2.sdl;
import derelict.sdl2.image;
import derelict.sdl2.mixer;
import derelict.sdl2.ttf;
import derelict.sdl2.net;

void main()
{
    SDL_Window* mainWindow;
    SDL_GLContext mainGLContext;

    try
    {
        DerelictGL3.load();

        // Load the SDL 2 library.
        DerelictSDL2.load();
.
        DerelictSDL2Image.load();
        DerelictSDL2Mixer.load();
        DerelictSDL2ttf.load();
        DerelictSDL2Net.load();
    }
    catch(Exception e){}
    finally{}

    // Initialise SDL
    if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 ) {
        throw new Exception("SDL initialization failed");
    }

    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION,3);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION,3);

    Uint32 flags = SDL_WINDOW_SHOWN|SDL_WINDOW_OPENGL;
    int width = 1024;
    int height = 768;

    mainWindow = SDL_CreateWindow("SDL2 OpenGL Example", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, flags);
    mainGLContext = SDL_GL_CreateContext(mainWindow);

    DerelictGL3.reload();

    SDL_DestroyWindow(mainWindow);
    SDL_Quit();
}

The issue will still occur even if everything below SDL_GL_SetAttribute() is commented out.

Additionally, derelict throws an exception when trying load SDL, but I think this is fairly common:

derelict.util.exception.SymbolLoadException@../../.dub/packages/derelict-util-2.0.4/source/derelict/util/exception.d(35): Failed to load symbol SDL_QueueAudio from shared library libSDL2.so

I am running Elementary OS and have used apt-get to ensure that SDL is up to date.

Thank you very much for your help.

Max Alibaev
  • 681
  • 7
  • 17
  • eh, I don't use Derelict and don't know how it works here, but I'm skeptical of a load exception being something you can just ignore. If it can't load that symbol, it might have not been able to finish loading other symbols too - including one you need like the SDL_init function. – Adam D. Ruppe Mar 03 '16 at 19:52
  • @AdamD.Ruppe Thank you. I misunderstood what this page on derelict loader exceptions was saying. (https://derelictorg.github.io/using/fail.html). When I add the callbacks it works alright. However, there are many things that fail to load so I probably have a bad SDL installation. – Daniel Ragsdale Mar 03 '16 at 20:52
  • The most likely cause of that error is that the SDL version you're using is too old. If you're using Derelict-SDL2 2.0.4 you also have to use SDL 2.0.4 – Cubic Mar 04 '16 at 11:52

2 Answers2

1

This is almost certainly down to SDL versioning issues.

My recommendation is to build the whole thing from source. It's not difficult by any means.

You can get SDL2 source here:

https://www.libsdl.org/download-2.0.php

Ensure you also get the extra projects too, i.e. sdl2 image, net, mixer and ttf. Links for these are at:

https://www.libsdl.org/projects/

To install them, your usual

./configure
make
sudo make install

will do the trick. Do SDL2 first, then the rest in whatever order you like.

Colin Grogan
  • 2,462
  • 3
  • 12
  • 12
1

I had this problem on Debian/Fedora/Ubuntu too. It is finding SDL 1.2 instead of your SDL 2.X and failing to bind to that. You need to specify what SDL version to use. Derelict should work fine with any 2.X version of SDL. You should not have to build SDL on any big name Linux distro. Do this to fix it:

// Change this
DerelictSDL2.load();
// To this
DerelictSDL2.load(SharedLibVersion(2, 0, 2));
Matthew Jones
  • 372
  • 2
  • 11
  • thanks it works. ... If I would have to recompile all SDL libraries it would probably deter me from experimenting with D. – Prokop Hapala Aug 15 '17 at 14:10