DerelictSDL2 crashes
lobo via Digitalmars-d
digitalmars-d at puremagic.com
Fri Aug 26 20:49:46 PDT 2016
On Friday, 26 August 2016 at 21:26:13 UTC, unDEFER wrote:
> Hello!
>
> I'm trying compile SDL "Hello, World"
>
> ---
> import std.stdio;
> import derelict.sdl2.sdl;
>
> //Screen dimension constants
> const int SCREEN_WIDTH = 640;
> const int SCREEN_HEIGHT = 480;
>
> int main()
> {
> DerelictSDL2.load();
>
> //The window we'll be rendering to
> SDL_Window* window = null;
>
> //The surface contained by the window
> SDL_Surface* screenSurface = null;
>
> //Initialize SDL
> if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
> {
> printf( "SDL could not initialize! SDL_Error: %s\n",
> SDL_GetError() );
> }
> else
> {
> //Create window
> window = SDL_CreateWindow( "SDL Tutorial",
> SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH,
> SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
> if( window == null )
> {
> printf( "Window could not be created! SDL_Error: %s\n",
> SDL_GetError() );
> }
> else
> {
> //Get window surface
> screenSurface = SDL_GetWindowSurface( window );
>
> //Fill the surface white
> SDL_FillRect( screenSurface, null, SDL_MapRGB(
> screenSurface.format, 0xFF, 0x00, 0x00 ) );
>
> //Update the surface
> SDL_UpdateWindowSurface( window );
>
> //Wait two seconds
> SDL_Delay( 2000 );
> }
> }
>
> //Destroy window
> SDL_DestroyWindow( window );
>
> //Quit SDL subsystems
> SDL_Quit();
>
> return 0;
> }
> ---
>
> $ dmd -I/path/to/DerelictSDL2/source
> -I/path/to/derelict-util-2.0.6/source main.d
> /path/to/DerelictSDL2/lib/libDerelictSDL2.a
> /path/to/derelict-util-2.0.6/lib/libDerelictUtil.a -gc
>
> It compiles but on running crashes (as shows valgrind) in
> SDL_FillRect function.
>
> BUT in gdb it runs successfully and I see red window.
> What I'm doing wrong? How gdb can make not working code working?
>
> dmd 2.071.1
>
> Thank you!
I tried your code in Arch x86_64 using dub and it worked for me.
This is the dub file I used:
---
name "testsdl"
targetType "executable"
dependency "derelict-sdl2" version=">=2.0.0"
dependency "derelict-util" version=">=2.0.6"
dependency "derelict-gl3" version=">=1.0.18"
---
If you're not familiar with dub and want to test these are the
steps I took.
0. Get dub [1]
1. mkdir -p testsdl/source
2. Copy your source code from OP into a file
"testsdl/source/app.d"
3. Copy the above dub config into a file "testsdl/dub.sdl"
4. cd testsdl; dub build
It should pull in the dependencies and build a program called
"testsdl".
bye,
lobo
[1] https://code.dlang.org/download
More information about the Digitalmars-d
mailing list