3 Replies - 1308 Views - Last Post: 08 March 2013 - 09:40 AM Rate Topic: -----

#1 absoluT88  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 08-March 13

How do you get SDL_Error() output?

Posted 08 March 2013 - 07:29 AM

I have recently been playing around with SDL and trying to get the hang of it, but have found something recently that bugs me a lot when testing for errors in my code. I found the function
SDL_Error()
, however I can't figure out how to receive the information that returns. So, for now I am kind of lost on how to test for errors besides returning bools or values and ending the program. Is there someway to easily create another console for
printf 
or
cout
statements?

Thank you.


P.S. The error I'm having right now is that
SDL_LoadBMP("Filename")
is remaining NULL. I assume it is not finding the file somehow, but I am not 100% sure. I have remade the file a couple times, saved as different .bmp formats and also checked the code.

Here is my load function, temp remains NULL and I can't figure it out:

SDL_Surface* Sprite::Load(char* File)
{
	SDL_Surface* temp = NULL;
	SDL_Surface* optimized = NULL;

	temp = SDL_LoadBMP(File);

	if(temp == NULL)
	{
		printf(SDL_GetError());
		return NULL;
	}
	
	optimized = SDL_DisplayFormatAlpha(temp);
	SDL_FreeSurface(temp);

	return optimized;
}


Thank you!

Is This A Good Question/Topic? 0
  • +

Replies To: How do you get SDL_Error() output?

#2 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1009
  • View blog
  • Posts: 4,208
  • Joined: 14-February 08

Re: How do you get SDL_Error() output?

Posted 08 March 2013 - 08:21 AM

You can add these lines to your code:

freopen( "CON", "wt", stdout );
freopen( "CON", "wt", stderr );


Was This Post Helpful? 0
  • +
  • -

#3 absoluT88  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 08-March 13

Re: How do you get SDL_Error() output?

Posted 08 March 2013 - 08:34 AM

Thank you stayscrisp, that is exactly a simple output solution I was looking for. And, also thank you for your SDL tutorials which I am following to learn. :)

I actually just figured out my problem... Somehow I had
int main(int argc, char* argv)

instead of
int main(int argc, char** argv)

and I was getting an access violation without an error.
Was This Post Helpful? 0
  • +
  • -

#4 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1009
  • View blog
  • Posts: 4,208
  • Joined: 14-February 08

Re: How do you get SDL_Error() output?

Posted 08 March 2013 - 09:40 AM

Yeah, you can write it like this:

int main(int argc, char *argv[])



Or like you have done.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1