Welcome! Log In Create A New Profile

Advanced

Error in simple SDL sample program

Posted by JoeNotCharles 
Error in simple SDL sample program
November 23, 2008 07:50AM
To get started with SDL, I'm trying to get the first sample program here running: [www.marsnomercy.org]

It works fine on my desktop, but on the Wii it fails strangely.

Here's the basic code of the main function:

int main(int argc, char **argv)
{
  //used surfaces
  SDL_Surface *screen = 0;
  SDL_Surface *screen_backup = 0;
  SDL_Surface *cursor = 0;
  SDL_Surface *bg_cursor = 0;
  SDL_Surface *temp = 0;


  //the system video is initialized
  if( SDL_Init(SDL_INIT_VIDEO) <0 )
  {
    //SDL_GetError() returns a description of the error
    printf("Errore init SDL: %s\n", SDL_GetError());
    pause();
          return 1;
  }

  //when exit, execute SDL_Quit to restore everything
  atexit(SDL_Quit);

  //a 32 bit integer used to store screen's flags
  Uint32 flags = SDL_HWSURFACE|SDL_DOUBLEBUF;

  //SDL_SetVideoMode is used to have screen associated to the monitor
  if(!( screen = SDL_SetVideoMode(DIM_H, DIM_V, 0,flags) ))
  {
      printf("Problemi con il settaggio dello schermo: %s\n", SDL_GetError());
      pause();
      return 1;
  }

  //the original cursor must be turned off
  SDL_ShowCursor(0);

  //the sight's image is associated to a temporany surface
  if((temp = IMG_ReadXPMFromArray(tmpsight)) ==NULL)
      {
      printf("Error loading XPM: %s\n", IMG_GetError());
      pause();
    return 1;
  }

...

I added a call to "pause()", which is just a function (basically taken from the template example) which prints "Paused" and waits for the HOME key, so I have time to read the error messages.

The original code used IMG_ReadFile to load a .png file from disk, and this was failing with a perfectly understandable "file not found" error message (because I was running with wiiload and didn't install that png anywhere.) But when I converted the .png to an XPM and switched to ReadXPMFromArray, so I didn't need a supplemental file, it just ends at that point and prints "Paused". (It works fine on my desktop.) So somehow the ReadXPMFromArray call is returning false, and not only is it not setting the SDL_Image error code, it's wiping out the rest of the line it's supposed to print.

I've confirmed it's definitely here that it's dying by sticking a bunch of printf("Checkpoint") calls in. Any idea why this could be failing?



Edited 1 time(s). Last edit at 11/23/2008 07:51AM by JoeNotCharles.
Re: Error in simple SDL sample program
November 23, 2008 02:54PM
Here is a sample which may help:

http://devkitpro.cvs.sourceforge.net/viewvc/devkitpro/SDL-Port/test/testbitmap.c?view=markup

The following command is used in it:

/* Load the bitmap */
bitmap = LoadXBM(screen, picture_width, picture_height, (Uint8 *)picture_bits);

if ( bitmap == NULL ) {
quit(1);
}
Re: Error in simple SDL sample program
November 23, 2008 09:40PM
Are you sure you have this function defined properly in your SDL_image lib? In the source code for SDL_image, this function is in an 'ifdef 'else block, where the 'else block defines a trivial version that returns NULL each time you call it.

If I disassemble this function in my SDL_image.a, I have the trivial version which returns NULL:

00000000 <IMG_ReadXPMFromArray>:
   0:	38 60 00 00 	li      r3,0
   4:	4e 80 00 20 	blr

I dumped the above on linux with:
powerpc-gekko-ar x libSDL_image.a IMG_xpm.o
powerpc-gekko-objdump -D IMG_xpm.o > IMG_xpm.s



Edited 1 time(s). Last edit at 11/23/2008 09:41PM by Michael.
Re: Error in simple SDL sample program
November 23, 2008 11:22PM
Quote
Michael
Are you sure you have this function defined properly in your SDL_image lib? In the source code for SDL_image, this function is in an 'ifdef 'else block, where the 'else block defines a trivial version that returns NULL each time you call it.

Well, that would explain it.

What a stupid way to stub that out. It should at least set the error code to "not implemented" or something. Even better would be to remove the function entirely so you get a compile error.
Sorry, only registered users may post in this forum.

Click here to login