Archived

This topic is now archived and is closed to further replies.

Cyberdrek

SDL Problem.

Recommended Posts

I know there aren''t alot of SDL users but hey, I have a bug, I''ve spent more than 3 days trying to debug using MSVC''s debugger and I still can''t seem to understand where the bug is. Hell, I don''t even know if it''s a bug. Here''s a bit of code. Explanation will follow. NB: HSSurface is a class that holds the following 2 things.   SDL_Surface *surface;   SDL_Rect rect; you can probably figure out that getSurface() returns a pointer to the surface and that getRect returns the SDL_Rect structure. with that in mind, take a look at the code.
  
// **

// ** Name: draw

// ** Desc: draws the sprite on a surface

// **

int HSSprite::draw( HSSurface screen )
{
   screen.changeRectW( image->w );
	screen.changeRectH( image->h );

   // **

   // ** Palettized screen modes will have a default palette (a standard

   // ** 8*8*4 colour cube), but if the image is palettized as well we can

   // ** use that palette for a nicer colour matching

   // **

   if ( image->format->palette && screen.getSurface()->format->palette )
	{
	   SDL_SetColors( screen.getSurface(), image->format->palette->colors, 0,
                     image->format->palette->ncolors );
   }

   // ** Blit onto the screen surface   

   if( SDL_BlitSurface( image, NULL, screen.getSurface(), &(screen.getRect()) ) < 0 )
       fprintf( stderr, "BlitSurface error: %s\n", SDL_GetError() );

   // ** Update modified rectangles

   SDL_UpdateRect( screen.getSurface(), 0, 0, image->w, image->h );

   return( 1 );
};
  
All right, I''ve limited my problem to this function. Oh, I forgot to mention that I''ve created Classes as I thought it would be a way to make my life easier for the purpose that I have. Anyways, the problems aren''t from the classes. It''s just that darn function. On to the problem: The first time this function is called, it draws the sprite perfectly on the screen. The second time I call the fuction, it closes the app. I''m not sure why though as I''ve used this exact same function in 2 other projects and it worked fine. Again, as I''ve mentionned, I''ve spent quite a bit of time trying to figure it out but I can''t seem to pinpoint the problem. "And that''s the bottom line cause I said so!" Cyberdrek Headhunter Soft A division of DLC Multimedia
Resist Windows XP''s Invasive Production Activation Technology! "gitty up" -- Kramer /(bb|[^b]{2})/ that is the Question -- ThinkGeek.com

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Try posting under Cone3D''s forum under the Affiliates section
of the forums, he''s done some tutorials(which you probably know
but if you don''t, Cone3d is hosted by gamedev.net)

and could you edit the part where you say there aren''t a lot
of SDL users, I really like it and I''d like to see it be more
widespread, lots of people do use it besides.

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
Try posting under Cone3D''s forum under the Affiliates section
of the forums, he''s done some tutorials(which you probably know
but if you don''t, Cone3d is hosted by gamedev.net)

and could you edit the part where you say there aren''t a lot
of SDL users, I really like it and I''d like to see it be more
widespread, lots of people do use it besides.


Why would I edit the message on the count that we like SDL. Saying that there aren''t alot of people who use it is a reality, not a desire. I mean compared to OGL and DX, there really aren''t alot of users that use it at the moment, I know, that under linux, it is the best choice you could have. That''s why I tried the Windows version and now I use it for both. So the point is, I was just stating a fact.



"And that''s the bottom line cause I said so!"

** I WANT TO BE THE MODERATOR FOR THE LINUX FORUM **

Cyberdrek
Headhunter Soft
A division of DLC Multimedia

Resist Windows XP''s Invasive Production Activation Technology!

"gitty up" -- Kramer
/(bb|[^b]{2})/ that is the Question -- ThinkGeek.com

Share this post


Link to post
Share on other sites
If all else fails, turn to Ye Olde Faithful debugging method: stick more fprintf calls in there. One after each function call, to see exactly which line it''s crashing on. And make sure the log file is being flushed to disk all the time: use fflush for this. It probably won''t be necessary, but better to be safe than sorry: call fflush after every fprintf and you know that, when your program crashes, everything you logged is in that file.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]

Share this post


Link to post
Share on other sites
quote:
Original post by Kylotan
If all else fails, turn to Ye Olde Faithful debugging method: stick more fprintf calls in there. One after each function call, to see exactly which line it''s crashing on. And make sure the log file is being flushed to disk all the time: use fflush for this. It probably won''t be necessary, but better to be safe than sorry: call fflush after every fprintf and you know that, when your program crashes, everything you logged is in that file.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]


I know about the good old debug methods, and I''ve used them but all the data is correct, I don''t know why SDL seems to have a problem with my classes but what the heck, I''ve redone the whole project in standard C. Everything seems back to normal. I hope... Thanks for the input though...



"And that''s the bottom line cause I said so!"

** I WANT TO BE THE MODERATOR FOR THE LINUX FORUM **

Cyberdrek

Resist Windows XP''s Invasive Production Activation Technology!

"gitty up" -- Kramer
/(bb|[^b]{2})/ that is the Question -- ThinkGeek.com
Hash Bang Slash bin Slash Bash -- #!/bin/bash

Share this post


Link to post
Share on other sites
The point of adding more fprintf calls is not to see whether your data is correct or not, it''s to see exactly which line it crashes on. That lets you narrow down your debugging efforts.

Share this post


Link to post
Share on other sites
quote:
Original post by Kylotan
The point of adding more fprintf calls is not to see whether your data is correct or not, it''s to see exactly which line it crashes on. That lets you narrow down your debugging efforts.

You could always (learn to) use the debugger instead...

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!

Share this post


Link to post
Share on other sites