Skip to main content
gamedev.net
🔒 Locked 🎲 GameMaker

Switch/Case problem

Started by Mullvalen 7 replies 1.3k views
Original Post
Mullvalen
Mullvalen
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;
     }
}

My blog about personal development for studying people - www.tricktolearn.com
Mullvalen
Mullvalen
Oh...no, the program does compile. The problem is that the program runs both case 3 and 4
My blog about personal development for studying people - www.tricktolearn.com
Argus2
Argus2
And you are completely sure that 'render_24bit' will never call 'render_32bit' ?
Mullvalen
Mullvalen
Yep, if i comment out case 4 everything works completely fine
My blog about personal development for studying people - www.tricktolearn.com
rip-off
rip-off
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?
Mullvalen
Mullvalen
Because i want to render it front to back and SDL_BlitSurface doesnt provide that...
My blog about personal development for studying people - www.tricktolearn.com
haegarr
haegarr
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.
Mullvalen
Mullvalen
Thanks, i found the error, seemed like the last sprite where not loaded at all, therefore had a dummy surface which was 32-bit.
My blog about personal development for studying people - www.tricktolearn.com

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.