Sign in to follow this  

Switch/Case problem

This topic is 4338 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
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 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

This topic is 4338 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this