Jump to content
  • Advertisement
Sign in to follow this  
Mullvalen

Switch/Case problem

This topic is 4646 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This problem seem to be really fishy. As it it now, i have to comment out the call for the 32 bit rendering function. Else, the program will call that one too and thats no good. What could be wrong?
void fh_renderer::draw_sprite( int scrollx, int scrolly, fh_layer_list& l, SDL_Surface& dest )
{
     switch ( l.image->format->BytesPerPixel )
     {
     case 1:
          //render_8bit();
          break;
     case 2:
          //render_16bit();
          break;
     case 3:
          render_24bit( l.x - scrollx, l.y - scrolly, *l.image, dest );
          break;
     case 4:
//          render_32bit( l.x - scrollx, l.x - scrolly, *l.image, dest );
          break;
     }
}

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
I'd help you, but you never really described what was going wrong with your code.

Does it compile? If it compiles does the program crash? If it doesn't crash, what do you want it to do that it isn't doing?

Share this post


Link to post
Share on other sites
It looks like you are using SDL for your rendering. Why do you have different functions for rendering at different bitdpeths, seeing as SDL will do this for you?

Share this post


Link to post
Share on other sites
It is unlikely that the compiler introduces a bug like the one described in the OP, but who knows... Else you have should take into account to choose another compiler.

From the shown code snippet and the given description I assume that fh_renderer::draw_sprite is called twice. If you have no debugger at hand, you could try to do something like

void fh_renderer::draw_sprite( int scrollx, int scrolly, fh_layer_list& l, SDL_Surface& dest )
{
cout << "entered w/ " << l.image->format->BytesPerPixel << endl;
switch ( l.image->format->BytesPerPixel )
{
case 1:
//render_8bit();
break;
case 2:
//render_16bit();
break;
case 3:
render_24bit( l.x - scrollx, l.y - scrolly, *l.image, dest );
cout << "24 bit done\n";
break;
case 4:
render_32bit( l.x - scrollx, l.x - scrolly, *l.image, dest );
cout << "32 bit done\n";
break;
}
}


From the resulting sequence of output you could determine whether
(1) the 32 bit rendering was invoked by a second invocation of fh_renderer::draw_sprite, in which case "entering w/" and "24 bit done" as well as "entering w/" and "32 bit done" would occur,
(2) by a spurious invocation from inside fh_renderer::draw_sprite, in which case "24 bit done" and "32 bit done" would occur in direct sequence, or
(3) by an invocation from outside fh_renderer::draw_sprite, in which case "32 bit done" would not occur at all.

Share this post


Link to post
Share on other sites
Thanks, i found the error, seemed like the last sprite where not loaded at all, therefore had a dummy surface which was 32-bit.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!