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.

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 on other sites
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 on other sites
Oh...no, the program does compile. The problem is that the program runs both case 3 and 4

Share on other sites
And you are completely sure that 'render_24bit' will never call 'render_32bit' ?

Share on other sites
Yep, if i comment out case 4 everything works completely fine

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 on other sites
Because i want to render it front to back and SDL_BlitSurface doesnt provide that...

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 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.

1. 1
Rutin
28
2. 2
3. 3
4. 4
5. 5

• 13
• 11
• 10
• 13
• 20
• Forum Statistics

• Total Topics
632952
• Total Posts
3009432
• Who's Online (See full list)

There are no registered users currently online

×