www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Derelict / SDL error

reply "Paul" <paul example.com> writes:
Sorry this is a bit off topic but as there doesn't seem to be an 
active forum for Derelict atm....

This simple test code is giving me an error 'Error executing 
command run: Program exited with code -11' (or a seg fault if 
executed from a terminal). The problem line is:

SDL_RenderCopy(renderer, texture, &sourceRect, &destRect);

I've tried this call with the 'null' options as well as passing 
the address of the rects but neither works (I've also tried 
manually assigning the various struct components rather than 
using the c style initialisation in case that was the problem).

Any ideas please?

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

void main()
{
     scope(exit) SDL_Quit();

     DerelictSDL2.load();
     writeln( "SDL loaded ok");


     //init sdl
	if (SDL_Init(SDL_INIT_EVERYTHING) != 0){
		writeln("SDL_Init Error: ", 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: ", 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: " , SDL_GetError() );
		return;
	}
	
	//load a bitmap
	SDL_Surface *image = SDL_LoadBMP("./test.bmp");
	if (image == null){
		writeln( "SDL_LoadBMP error: " , SDL_GetError() );
		return;
	}	
	
	//create texture for bitmap
	SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, 
image);
	if (texture == null){
		writeln( "CreateTextureFromSurface error: " , 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);
	
		
}
Dec 08 2014
next sibling parent reply ketmar via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
On Mon, 08 Dec 2014 12:53:10 +0000
Paul via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:

 Sorry this is a bit off topic but as there doesn't seem to be an=20
 active forum for Derelict atm....
=20
 This simple test code is giving me an error 'Error executing=20
 command run: Program exited with code -11' (or a seg fault if=20
 executed from a terminal). The problem line is:
=20
 SDL_RenderCopy(renderer, texture, &sourceRect, &destRect);
=20
 I've tried this call with the 'null' options as well as passing=20
 the address of the rects but neither works (I've also tried=20
 manually assigning the various struct components rather than=20
 using the c style initialisation in case that was the problem).
=20
 Any ideas please?
=20
 import derelict.sdl2.sdl;
 import std.stdio;
=20
 void main()
 {
      scope(exit) SDL_Quit();
=20
      DerelictSDL2.load();
      writeln( "SDL loaded ok");
=20
=20
      //init sdl
 	if (SDL_Init(SDL_INIT_EVERYTHING) !=3D 0){
 		writeln("SDL_Init Error: ", SDL_GetError() );
 		return;
 	}
 	=09
 	//open a window
 	SDL_Window *window =3D SDL_CreateWindow("Window Title!", 100, 100,=20
 640, 480, SDL_WINDOW_SHOWN);
 	if (window =3D=3D null){
 		writeln("SDL_CreateWindow Error: ", SDL_GetError() );
 		return;
 	}=09
 	=09
 	//get a renderer (ie buffer), use software renderer for now
 	SDL_Renderer *renderer =3D SDL_CreateRenderer(window, -1,=20
 SDL_RENDERER_SOFTWARE);
 	if (renderer =3D=3D null){
 		writeln( "SDL_CreateRenderer Error: " , SDL_GetError() );
 		return;
 	}
 =09
 	//load a bitmap
 	SDL_Surface *image =3D SDL_LoadBMP("./test.bmp");
 	if (image =3D=3D null){
 		writeln( "SDL_LoadBMP error: " , SDL_GetError() );
 		return;
 	}=09
 =09
 	//create texture for bitmap
 	SDL_Texture *texture =3D SDL_CreateTextureFromSurface(renderer,=20
 image);
 	if (texture =3D=3D null){
 		writeln( "CreateTextureFromSurface error: " , SDL_GetError() );
 		return;
 	}	=09
 =09
      //copy to renderer at correct position & scale
      SDL_Rect sourceRect =3D { 0, 0, 64, 64 };
      SDL_Rect destRect =3D { 100, 100, 64, 64 };
      SDL_RenderCopy(renderer, texture, &sourceRect, &destRect);=09
 	=09
 =09
      //display and pause
      SDL_RenderPresent(renderer);
      SDL_Delay(2000);
 =09
 	=09
 }
this exact code is working for me. i just copypasted it and gave it test.bmp to work with.
Dec 08 2014
parent reply "Paul" <paul example.com> writes:
On Monday, 8 December 2014 at 13:08:58 UTC, ketmar via 
Digitalmars-d-learn wrote:
 On Mon, 08 Dec 2014 12:53:10 +0000
 Paul via Digitalmars-d-learn 
 <digitalmars-d-learn puremagic.com> wrote:

 Sorry this is a bit off topic but as there doesn't seem to be 
 an active forum for Derelict atm....
 
 This simple test code is giving me an error 'Error executing 
 command run: Program exited with code -11' (or a seg fault if 
 executed from a terminal). The problem line is:
 
 SDL_RenderCopy(renderer, texture, &sourceRect, &destRect);
 
 I've tried this call with the 'null' options as well as 
 passing the address of the rects but neither works (I've also 
 tried manually assigning the various struct components rather 
 than using the c style initialisation in case that was the 
 problem).
 
 Any ideas please?
 this exact code is working for me. i just copypasted it and 
 gave it
 test.bmp to work with.
Thanks for testing, must be something on my system then... I've no idea where to start looking for the problem though :(
Dec 08 2014
parent reply ketmar via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
On Mon, 08 Dec 2014 13:16:37 +0000
Paul via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:

 On Monday, 8 December 2014 at 13:08:58 UTC, ketmar via=20
 Digitalmars-d-learn wrote:
 On Mon, 08 Dec 2014 12:53:10 +0000
 Paul via Digitalmars-d-learn=20
 <digitalmars-d-learn puremagic.com> wrote:

 Sorry this is a bit off topic but as there doesn't seem to be=20
 an active forum for Derelict atm....
=20
 This simple test code is giving me an error 'Error executing=20
 command run: Program exited with code -11' (or a seg fault if=20
 executed from a terminal). The problem line is:
=20
 SDL_RenderCopy(renderer, texture, &sourceRect, &destRect);
=20
 I've tried this call with the 'null' options as well as=20
 passing the address of the rects but neither works (I've also=20
 tried manually assigning the various struct components rather=20
 than using the c style initialisation in case that was the=20
 problem).
=20
 Any ideas please?
=20
 this exact code is working for me. i just copypasted it and=20
 gave it
 test.bmp to work with.
=20 Thanks for testing, must be something on my system then... I've=20 no idea where to start looking for the problem though :(
i must admit that i'm on 32-bit GNU/Linux, so i can't say anything about 64-bit and/or non-GNU/Linux OSes.
Dec 08 2014
parent reply "Paul" <paul example.com> writes:
On Monday, 8 December 2014 at 13:23:12 UTC, ketmar via 
Digitalmars-d-learn wrote:
 On Mon, 08 Dec 2014 13:16:37 +0000
 Paul via Digitalmars-d-learn 
 <digitalmars-d-learn puremagic.com> wrote:

 On Monday, 8 December 2014 at 13:08:58 UTC, ketmar via 
 Digitalmars-d-learn wrote:
 On Mon, 08 Dec 2014 12:53:10 +0000
 Paul via Digitalmars-d-learn 
 <digitalmars-d-learn puremagic.com> wrote:

 Sorry this is a bit off topic but as there doesn't seem to 
 be an active forum for Derelict atm....
 
 This simple test code is giving me an error 'Error 
 executing command run: Program exited with code -11' (or a 
 seg fault if executed from a terminal). The problem line is:
 
 SDL_RenderCopy(renderer, texture, &sourceRect, &destRect);
 
 I've tried this call with the 'null' options as well as 
 passing the address of the rects but neither works (I've 
 also tried manually assigning the various struct components 
 rather than using the c style initialisation in case that 
 was the problem).
 
 Any ideas please?
 this exact code is working for me. i just copypasted it and 
 gave it
 test.bmp to work with.
Thanks for testing, must be something on my system then... I've no idea where to start looking for the problem though :(
i must admit that i'm on 32-bit GNU/Linux, so i can't say anything about 64-bit and/or non-GNU/Linux OSes.
I added this around the problem line to catch the problem: try{ SDL_RenderCopy(renderer, texture, &sourceRect, &destRect); } catch{} finally { writeln( "Error: " , SDL_GetError() ); } The program now works from a terminal as expected (!) BUT when SDL_RenderCopy is called SDL_GetError() shows an 'error code' (or just some address/value as it is different each time).
Dec 08 2014
next sibling parent reply ketmar via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
On Mon, 08 Dec 2014 13:37:20 +0000
Paul via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:

 The program now works from a terminal as expected (!) BUT when=20
 SDL_RenderCopy is called SDL_GetError() shows an 'error code' (or=20
 just some address/value as it is different each time).
FYI: SDL_GetError() returns 'char*', not string. you can print error message with this code, for example: private void sdl_print_error () trusted nothrow nogc { import core.stdc.stdio : stderr, fprintf; auto sdl_error =3D SDL_GetError(); fprintf(stderr, "SDL ERROR: %s\n", sdl_error); } besides, i don't think that you'll get something sane from `SDL_GetError()` in the case of segfault.
Dec 08 2014
parent "Paul" <paul example.com> writes:
On Monday, 8 December 2014 at 13:47:47 UTC, ketmar via 
Digitalmars-d-learn wrote:
 On Mon, 08 Dec 2014 13:37:20 +0000
 Paul via Digitalmars-d-learn 
 <digitalmars-d-learn puremagic.com> wrote:
 besides, i don't think that you'll get something sane from
 `SDL_GetError()` in the case of segfault.
Your're right, no help at all. I should also have checked that when I forced errors the SDL error messages were being displayed (which they weren't of course). That'll teach me to play while at work ;)
Dec 08 2014
prev sibling parent reply Mike Parker <aldacron gmail.com> writes:
On 12/8/2014 10:37 PM, Paul wrote:

 I added this around the problem line to catch the problem:

      try{
          SDL_RenderCopy(renderer, texture, &sourceRect, &destRect);
      } catch{}
      finally {
          writeln( "Error: " , SDL_GetError() );
      }

 The program now works from a terminal as expected (!) BUT when
 SDL_RenderCopy is called SDL_GetError() shows an 'error code' (or just
 some address/value as it is different each time).
import std.conv : to; writeln( "Error: ", to!string( SDL_GetError() ));
Dec 08 2014
parent reply "Paul" <paul example.com> writes:
On Monday, 8 December 2014 at 13:48:27 UTC, Mike Parker wrote:

 import std.conv : to;
 writeln( "Error: ", to!string( SDL_GetError() ));
Cleaner! Any ideas where to look for the source of the problem?
Dec 08 2014
parent reply ketmar via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
On Mon, 08 Dec 2014 14:13:54 +0000
Paul via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:

 On Monday, 8 December 2014 at 13:48:27 UTC, Mike Parker wrote:
=20
 import std.conv : to;
 writeln( "Error: ", to!string( SDL_GetError() ));
=20 Cleaner!
ah, sure. i just wanted to use libc's fprintf() to avoid importing std.stdio, so copy-pasted that code. but you get the idea anyway. ;-)
 Any ideas where to look for the source of the problem?
sorry, no. you can try to update SDL2 to the latest version and Derelict bindings to git head though. i don't think that this will help, but you at least be sure that the problem is not in some obsolete version of the code.
Dec 08 2014
parent "Paul" <paul example.com> writes:
On Monday, 8 December 2014 at 14:35:17 UTC, ketmar via 
Digitalmars-d-learn wrote:
 On Mon, 08 Dec 2014 14:13:54 +0000
 Paul via Digitalmars-d-learn 
 <digitalmars-d-learn puremagic.com> wrote:

 On Monday, 8 December 2014 at 13:48:27 UTC, Mike Parker wrote:
 
 import std.conv : to;
 writeln( "Error: ", to!string( SDL_GetError() ));
Cleaner!
ah, sure. i just wanted to use libc's fprintf() to avoid importing std.stdio, so copy-pasted that code. but you get the idea anyway. ;-)
 Any ideas where to look for the source of the problem?
sorry, no. you can try to update SDL2 to the latest version and Derelict bindings to git head though. i don't think that this will help, but you at least be sure that the problem is not in some obsolete version of the code.
I've only just installed SDL/Derelict on this machine so it should be up to date. I'll keep digging...
Dec 08 2014
prev sibling parent reply "Jack" <Jackoz530 gmail.com> writes:
On Monday, 8 December 2014 at 12:53:11 UTC, Paul wrote:
 Sorry this is a bit off topic but as there doesn't seem to be 
 an active forum for Derelict atm....

 This simple test code is giving me an error 'Error executing 
 command run: Program exited with code -11' (or a seg fault if 
 executed from a terminal). The problem line is:

 SDL_RenderCopy(renderer, texture, &sourceRect, &destRect);

 I've tried this call with the 'null' options as well as passing 
 the address of the rects but neither works (I've also tried 
 manually assigning the various struct components rather than 
 using the c style initialisation in case that was the problem).

 Any ideas please?

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

 void main()
 {
     scope(exit) SDL_Quit();

     DerelictSDL2.load();
     writeln( "SDL loaded ok");


     //init sdl
 	if (SDL_Init(SDL_INIT_EVERYTHING) != 0){
 		writeln("SDL_Init Error: ", 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: ", 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: " , SDL_GetError() );
 		return;
 	}
 	
 	//load a bitmap
 	SDL_Surface *image = SDL_LoadBMP("./test.bmp");
 	if (image == null){
 		writeln( "SDL_LoadBMP error: " , SDL_GetError() );
 		return;
 	}	
 	
 	//create texture for bitmap
 	SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, 
 image);
 	if (texture == null){
 		writeln( "CreateTextureFromSurface error: " , 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);
 	
 		
 }
I'm running ArchLinux 64-bit on Vbox and tested out the code. There haven't been any problems. Have you tried updating whatever tools you're using?(dmd, dub, etc....) Might've been an outdated piece of software that's been making the fuss.
Dec 08 2014
parent reply "Paul" <paul example.com> writes:
On Monday, 8 December 2014 at 17:48:55 UTC, Jack wrote:
 I'm running ArchLinux 64-bit on Vbox and tested out the code.
 There haven't been any problems. Have you tried updating
 whatever tools you're using?(dmd, dub, etc....) Might've been 
 an outdated piece of software that's been making the fuss.
Thanks for that. I've just tried the code on a different machine (latest Lubuntu on a 32 bit laptop, latest SDL, dmd and current dub binary) and it has exactly the same problem. Can't think what the problem might be other than something wrong with the way I've compiled SDL...??
Dec 08 2014
parent reply "Paul" <paul example.com> writes:
On Monday, 8 December 2014 at 21:01:40 UTC, Paul wrote:
 On Monday, 8 December 2014 at 17:48:55 UTC, Jack wrote:
 I'm running ArchLinux 64-bit on Vbox and tested out the code.
 There haven't been any problems. Have you tried updating
 whatever tools you're using?(dmd, dub, etc....) Might've been 
 an outdated piece of software that's been making the fuss.
Thanks for that. I've just tried the code on a different machine (latest Lubuntu on a 32 bit laptop, latest SDL, dmd and current dub binary) and it has exactly the same problem. Can't think what the problem might be other than something wrong with the way I've compiled SDL...??
The only 'warning' during compilation of SDL is about dbus not being used so I installed all the related *dev files I could find (and recompiled after each) but despite dbus now being flagged as 'used' it was to no avail. Thinking...
Dec 09 2014
parent reply "Jack" <Jackoz530 gmail.com> writes:
On Tuesday, 9 December 2014 at 10:19:38 UTC, Paul wrote:
 On Monday, 8 December 2014 at 21:01:40 UTC, Paul wrote:
 On Monday, 8 December 2014 at 17:48:55 UTC, Jack wrote:
 I'm running ArchLinux 64-bit on Vbox and tested out the code.
 There haven't been any problems. Have you tried updating
 whatever tools you're using?(dmd, dub, etc....) Might've been 
 an outdated piece of software that's been making the fuss.
Thanks for that. I've just tried the code on a different machine (latest Lubuntu on a 32 bit laptop, latest SDL, dmd and current dub binary) and it has exactly the same problem. Can't think what the problem might be other than something wrong with the way I've compiled SDL...??
The only 'warning' during compilation of SDL is about dbus not being used so I installed all the related *dev files I could find (and recompiled after each) but despite dbus now being flagged as 'used' it was to no avail. Thinking...
Can't really think of anything that can solve your problem. Only time I had a seg fault is calling a method from an uninitialized class. You can try to get a debugger and/or a gui that comes with it(personally I use gdb with ddd) to find something out. Sorry but this is all the suggestions I can give to you, I'm not really an expert in Derelict or Libraries or something.
Dec 09 2014
parent reply "Paul" <paul example.com> writes:
On Tuesday, 9 December 2014 at 13:34:56 UTC, Jack wrote:
 Can't really think of anything that can solve your problem. 
 Only time I had a seg fault is calling a method from an 
 uninitialized class.
 You can try to get a debugger and/or a gui that comes with 
 it(personally I use gdb with ddd) to find something out.
 Sorry but this is all the suggestions I can give to you, I'm 
 not really an expert in Derelict or Libraries or something.
I don't fancy introduing another layer of complexity in a debugger at present! I wonder if it's the .bmp that's causing the problem. I can't quite figure how to get Derelict SDL_Image into my project at present (dub doesn't fetch it if I add import derelict.sdl.image; ) otherwise I'd try a png or something. Can't really see it being that anyway but worth a try I suppose. Thanks for trying anway. :D
Dec 09 2014
parent reply Mike Parker <aldacron gmail.com> writes:
On 12/10/2014 12:19 AM, Paul wrote:
 I don't fancy introduing another layer of complexity in a debugger at
 present! I  wonder if it's the .bmp that's causing the problem. I can't
 quite figure how to get Derelict SDL_Image into my project at present
 (dub doesn't fetch it if I add import derelict.sdl.image; ) otherwise
 I'd try a png or something. Can't really see it being that anyway but
 worth a try I suppose.
dub doesn't know anything about DerelictSDL2Image (and even if it did, just importing it isn't going to tell dub about it -- you would need to add it to your dub.json as a dependency). That's because DerelictSDL2Image is not an independent package. It's part of DerelictSDL2. You need to call DerelictSDL2Image.load() to load the SDL2_image shared library, then you can use it.
Dec 09 2014
parent reply "Paul" <paul example.com> writes:
On Tuesday, 9 December 2014 at 15:40:00 UTC, Mike Parker wrote:
 On 12/10/2014 12:19 AM, Paul wrote:
 dub doesn't know anything about DerelictSDL2Image (and even if 
 it did, just importing it isn't going to tell dub about it -- 
 you would need to add it to your dub.json as a dependency). 
 That's because DerelictSDL2Image is not an independent package. 
 It's part of DerelictSDL2. You need to call 
 DerelictSDL2Image.load() to load the SDL2_image shared library, 
 then you can use it.
I realise both of those, but I can't find the relevant package name, I thought it might be like this.. "dependencies": { "derelict-sdl2":"~>1.0.0", "derelict-gl3":">=1.0.0", "derelict-sdl2-image":">=1.0.0" } I've tried several variations but no joy.
Dec 09 2014
parent reply "Paul" <paul example.com> writes:
On Tuesday, 9 December 2014 at 15:48:32 UTC, Paul wrote:
 On Tuesday, 9 December 2014 at 15:40:00 UTC, Mike Parker wrote:
 On 12/10/2014 12:19 AM, Paul wrote:
 dub doesn't know anything about DerelictSDL2Image (and even if 
 it did, just importing it isn't going to tell dub about it -- 
 you would need to add it to your dub.json as a dependency). 
 That's because DerelictSDL2Image is not an independent 
 package. It's part of DerelictSDL2. You need to call 
 DerelictSDL2Image.load() to load the SDL2_image shared 
 library, then you can use it.
I realise both of those, but I can't find the relevant package name, I thought it might be like this.. "dependencies": { "derelict-sdl2":"~>1.0.0", "derelict-gl3":">=1.0.0", "derelict-sdl2-image":">=1.0.0" } I've tried several variations but no joy.
Whoa, I read that wrong - I'm sure I tried just adding DerelictSDL2Image.load() to my program an it didnt work. Trying again.
Dec 09 2014
parent reply "Paul" <paul example.com> writes:
On Tuesday, 9 December 2014 at 15:53:11 UTC, Paul wrote:
 Whoa, I read that wrong - I'm sure I tried just adding 
 DerelictSDL2Image.load() to my program an it didnt work. Trying 
 again.
The top of my app.d looks like this: import derelict.sdl2.sdl; import std.stdio; import std.conv; void main() { scope(exit) { SDL_Quit(); } DerelictSDL2.load(); DerelictSDL2Image.load(); When I run dub that last line gives me: source/app.d(15): Error: undefined identifier DerelictSDL2Image The deps in dub.json are: "dependencies": { "derelict-sdl2":"~>1.0.0", "derelict-gl3":">=1.0.0" } Thanks for perseversing with my density.
Dec 09 2014
parent reply "anonymous" <anonymous example.com> writes:
On Tuesday, 9 December 2014 at 16:12:35 UTC, Paul wrote:
 import derelict.sdl2.sdl;
 import std.stdio;
 import std.conv;

 void main()
 {
     scope(exit) {
 		
 	SDL_Quit();
     }

     DerelictSDL2.load();
     DerelictSDL2Image.load();

 When I run dub that last line gives me:

 source/app.d(15): Error: undefined identifier DerelictSDL2Image
You're missing `import derelict.sdl2.image;`.
Dec 09 2014
parent reply "Paul" <paul example.com> writes:
On Tuesday, 9 December 2014 at 22:27:43 UTC, anonymous wrote:
 On Tuesday, 9 December 2014 at 16:12:35 UTC, Paul wrote:
 import derelict.sdl2.sdl;
 import std.stdio;
 import std.conv;

 void main()
 {
    scope(exit) {
 		
 	SDL_Quit();
    }

    DerelictSDL2.load();
    DerelictSDL2Image.load();

 When I run dub that last line gives me:

 source/app.d(15): Error: undefined identifier DerelictSDL2Image
You're missing `import derelict.sdl2.image;`.
Adding that reveals that I need to add SDL_image 2.0 (I didn't know that that wasn't a part of the standard SDL install) so I've compiled that too. I now get the error: Unsupported image format whether I use a png or jpg. IMG_Load() does however work in the same way as SDL_LoadBMP if I feed it a .bmp - the image is displayed but there is a seg fault. Nightmare.
Dec 10 2014
next sibling parent reply ketmar via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
On Wed, 10 Dec 2014 08:59:36 +0000
Paul via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:

 Adding that reveals that I need to add SDL_image 2.0 (I didn't=20
 know that that wasn't a part of the standard SDL install) so I've=20
 compiled that too. I now get the error:
=20
 Unsupported image format
=20
 whether I use a png or jpg.
do you have the corresponding libraries installed? SDL_Image uses libpng and libjpeg for decoding images, so if you don't have those installed (with corresponding -dev if your system needs that) you will not be able to load images in those formats. also please note that libpng has two incompatible versions, so double-check README for SDL_Image.
Dec 10 2014
parent reply "Paul" <paul example.com> writes:
On Wednesday, 10 December 2014 at 09:07:56 UTC, ketmar via 
Digitalmars-d-learn wrote:
 do you have the corresponding libraries installed? SDL_Image 
 uses
 libpng and libjpeg for decoding images, so if you don't have 
 those
 installed (with corresponding -dev if your system needs that) 
 you will
 not be able to load images in those formats.

 also please note that libpng has two incompatible versions, so
 double-check README for SDL_Image.
On Wednesday, 10 December 2014 at 09:07:56 UTC, ketmar via Digitalmars-d-learn wrote:
 do you have the corresponding libraries installed? SDL_Image 
 uses
 libpng and libjpeg for decoding images, so if you don't have 
 those
 installed (with corresponding -dev if your system needs that) 
 you will
 not be able to load images in those formats.

 also please note that libpng has two incompatible versions, so
 double-check README for SDL_Image.
The readme for SDL_image doesn't say anything about incompatible versions of libpng - I have version 1.2.46 installed along with the dev files. It also says zlib is required and those are also installed. On the project page[1] is lists libpng 1.5.7 as being used for the pre-built binaries (presumably for Win) although the link it provides is dead. libpng 1.5.2 is the nearest version on that project page[2]. I built that then rebuilt SDL_image. dub --force now gives me: IMG_Load error: Failed loading png_set_longjmp_fn: /lib/i386-linux-gnu/libpng12.so.0: undefined symbol: _png_set_longjmp_fn Which looks like it is still referring to the old version of libpng. I downloaded the source for the latest version of libpng but there is no simple install procedure - the configuration required is beyond my level of knowledge. This thread has degenerated into a discussion of the set up of my OS which is miles off topic and should probably be abandoned. Thanks for trying all the same. [1]https://www.libsdl.org/projects/SDL_image/ [2]http://www.libpng.org/pub/png/libpng.html
Dec 10 2014
parent reply Mike Parker <aldacron gmail.com> writes:
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.
Dec 10 2014
parent reply "Paul" <paul example.com> writes:
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.
Dec 10 2014
parent reply "Paul" <paul example.com> writes:
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.
Dec 10 2014
parent reply "Paul" <paul example.com> writes:
On Wednesday, 10 December 2014 at 18:58:15 UTC, Paul wrote:

 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.
Just added SDL_image to this 64 bit system and the program works as expected with a *.png format image. http://picpaste.com/Screenshot_-_101214_-_19_14_15-cUuIeloG.png
Dec 10 2014
parent reply Mike Parker <aldacron gmail.com> writes:
On 12/11/2014 4:17 AM, Paul wrote:
 On Wednesday, 10 December 2014 at 18:58:15 UTC, Paul wrote:

 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.
Just added SDL_image to this 64 bit system and the program works as expected with a *.png format image. http://picpaste.com/Screenshot_-_101214_-_19_14_15-cUuIeloG.png
More evidence pointing toward the system configuration on the problem machines. I'm quite far from being a Linux guru, but at this point I would be looking at removing the binaries I've compiled myself and installing the binary packages through apt-get (given that you're using Mint). If the test program runs with those shared libraries, then you can start looking for what went wrong when you compiled them yourself if you feel motivated to dig into it.
Dec 10 2014
parent "Paul" <paul example.com> writes:
On Thursday, 11 December 2014 at 00:36:08 UTC, Mike Parker wrote:
 More evidence pointing toward the system configuration on the 
 problem machines. I'm quite far from being a Linux guru, but at 
 this point I would be looking at removing the binaries I've 
 compiled myself and installing the binary packages through 
 apt-get (given that you're using Mint). If the test program 
 runs with those shared libraries, then you can start looking 
 for what went wrong when you compiled them yourself if you feel 
 motivated to dig into it.
The only thing I'd compiled when the error first arose was SDL, I installed xorg-dev files via apt-get, dmd and dub were ready made binaries. As SDL isn't available via the repos I'm not sure what else I can do.
Dec 11 2014
prev sibling parent reply Mike Parker <aldacron gmail.com> writes:
On 12/10/2014 5:59 PM, Paul wrote:

 Adding that reveals that I need to add SDL_image 2.0 (I didn't know that
 that wasn't a part of the standard SDL install) so I've compiled that
 too. I now get the error:

 Unsupported image format

 whether I use a png or jpg.
int flags = IMG_INIT_PNG | IMG_INIT_JPG; if( IMG_Init( flags ) != flags ) { ... } https://www.libsdl.org/projects/SDL_image/docs/SDL_image_8.html
 IMG_Load() does however work in the same way as SDL_LoadBMP if I feed it
 a .bmp - the image is displayed but there is a seg fault.
I recommend you give it a try with a hardware renderer and see what happens. That could potentially narrow it down a bit. Also, though this is unrelated (I just noticed it when looking at your code again), I strongly recommend you move the line scope( exit ) SDL_Quit(); to somewhere after DerelictSDL2.load(). If the SDL shared library fails to load for some reason, an exception will be thrown and as the function exits the runtime will happily call SDL_Quit -- even though it will very likely be a null pointer at that point since the library never loaded. Always keep in mind when using Derelict that you're working through function pointers since the shared libraries are loaded manually. If the library fails to load because it was missing, none of the function pointers will be valid. If loading aborts because a function is missing, only the ones loaded before it will have been properly set, so that case should be treated as if they are all invalid.
Dec 10 2014
parent "Paul" <paul example.com> writes:
On Wednesday, 10 December 2014 at 12:10:23 UTC, Mike Parker wrote:
 Also, though this is unrelated (I just noticed it when looking 
 at your code again), I strongly recommend you move the line

 scope( exit ) SDL_Quit();

 to somewhere after DerelictSDL2.load(). If the SDL shared 
 library fails to load for some reason, an exception will be 
 thrown and as the function exits the runtime will happily call 
 SDL_Quit -- even though it will very likely be a null pointer 
 at that point since the library never loaded. Always keep in 
 mind when using Derelict that you're working through function 
 pointers since the shared libraries are loaded manually. If the 
 library fails to load because it was missing, none of the 
 function pointers will be valid. If loading aborts because a 
 function is missing, only the ones loaded before it will have 
 been properly set, so that case should be treated as if they 
 are all invalid.
I see, makes sense!
Dec 10 2014