DerelictSDL2 crashes

unDEFER via Digitalmars-d digitalmars-d at puremagic.com
Fri Aug 26 14:26:13 PDT 2016


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!


More information about the Digitalmars-d mailing list