Derelict / SDL error

Paul via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Dec 10 10:58:14 PST 2014


On Wednesday, 10 December 2014 at 18:06:08 UTC, Paul wrote:
> On Wednesday, 10 December 2014 at 16:58:57 UTC, Mike Parker 
> wrote:
>> On 12/11/2014 12:31 AM, Paul wrote:
>>
>>>
>>> This thread has degenerated into a discussion of the set up 
>>> of my OS
>>> which is miles off topic and should probably be abandoned.
>>
>> Maybe not. The trouble is that others have been able to 
>> compile and run the same code without error. Given that you 
>> are still unable to, that puts your system configuration in 
>> the spotlight. Your error with libpng points even more in that 
>> direction. If that turns out to be the culprit, it wouldn't be 
>> the first time someone has had run-time errors because of 
>> something not quite right on their system.
>>
>> Without a failure that others can reproduce, there's not much 
>> for anyone to do other than make (hopefully educated) guesses. 
>> I'm happy to keep doing so until it's either resolved or I run 
>> out of ideas.
>
> I appreciate that Mike, I would really like to get this sorted 
> so I can get on with learning D. I read up on the procedure for 
> building the latest libpng which I did. It gives same error 
> message as using the earlier version.
>
> It seems to me that trying to use SDL_image rather than the 
> 'built in' *.bmp handling might be compounding the problem 
> (unless libpng is called upon to render bmps as well?). I don't 
> know what to try next I'm afraid.

On another of my machines (64 bit Linux 17 XFCE) I've just 
installed dmd (64 bit) and dub binary, xorg-dev (includes libpng 
1.2.50) and built SDL2. This program now works without any errors:

import derelict.sdl2.sdl;
import std.stdio;
import std.conv;



void main()
{


     DerelictSDL2.load();

     scope(exit) SDL_Quit();

     //init sdl
	if (SDL_Init(SDL_INIT_EVERYTHING) != 0){
		writeln("SDL_Init Error: ", to!string( SDL_GetError() ));
		return;
	}
		
	//open a window
	SDL_Window *window = SDL_CreateWindow("Window Title!", 100, 100, 
640, 480, SDL_WINDOW_SHOWN);
	if (window == null){
		writeln("SDL_CreateWindow Error: ", to!string(SDL_GetError() ));
		return;
	}	
		
	//get a renderer (ie buffer), use software renderer for now
	SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 
SDL_RENDERER_SOFTWARE);
	if (renderer == null){
		writeln( "SDL_CreateRenderer Error: " , to!string( 
SDL_GetError() ));
		return;
	}
	
	//load a bitmap
	SDL_Surface *image = SDL_LoadBMP("./test.bmp");
	if (image == null){
		writeln( "SDL_LoadBMP error: " , to!string(SDL_GetError() ));
		return;
	}	
	
	//create texture for bitmap
	SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, 
image);
	if (texture == null){
		writeln( "CreateTextureFromSurface error: " , 
to!string(SDL_GetError() ));
		return;
	}		
	
     //copy to renderer at correct position & scale
     SDL_Rect sourceRect = { 0, 0, 64, 64 };
     SDL_Rect destRect = { 100, 100, 64, 64 };
     SDL_RenderCopy(renderer, texture, &sourceRect, &destRect);	
		
	
     //display and pause
     SDL_RenderPresent(renderer);
     SDL_Delay(2000);
	
		
}

The two machines on which errors occur are a Mint 13 (32 bit) box 
and an ageing laptop with Lubuntu 14.04. I've followed the same 
procedures but the 64 bit obviously has the 64 bit dmd compiler.




More information about the Digitalmars-d-learn mailing list