Jump to page: 1 24  
Page
Thread overview
Derelict / SDL error
Dec 08, 2014
Paul
Dec 08, 2014
ketmar
Dec 08, 2014
Paul
Dec 08, 2014
ketmar
Dec 08, 2014
Paul
Dec 08, 2014
ketmar
Dec 08, 2014
Paul
Dec 08, 2014
Mike Parker
Dec 08, 2014
Paul
Dec 08, 2014
ketmar
Dec 08, 2014
Paul
Dec 08, 2014
Jack
Dec 08, 2014
Paul
Dec 09, 2014
Paul
Dec 09, 2014
Jack
Dec 09, 2014
Paul
Dec 09, 2014
Mike Parker
Dec 09, 2014
Paul
Dec 09, 2014
Paul
Dec 09, 2014
Paul
Dec 09, 2014
anonymous
Dec 10, 2014
Paul
Dec 10, 2014
ketmar
Dec 10, 2014
Paul
Dec 10, 2014
Mike Parker
Dec 10, 2014
Paul
Dec 10, 2014
Paul
Dec 10, 2014
Paul
Dec 11, 2014
Mike Parker
Dec 11, 2014
Paul
Dec 10, 2014
Mike Parker
Dec 10, 2014
Paul
December 08, 2014
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);
	
		
}
December 08, 2014
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?
> 
> 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);
> 
> 
> }
this exact code is working for me. i just copypasted it and gave it test.bmp to work with.


December 08, 2014
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 :(

December 08, 2014
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.


December 08, 2014
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).





December 08, 2014
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 SDL_RenderCopy is called SDL_GetError() shows an 'error code' (or 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 = 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.


December 08, 2014
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() ));

December 08, 2014
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 ;)



December 08, 2014
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?
December 08, 2014
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.


« First   ‹ Prev
1 2 3 4