• Welcome to Dark Bit Factory & Gravity.
 

[C++] Bitmap Scroller: Strings And Things.

Started by Clyde, September 07, 2009

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

Clyde

I thought I had this on the 4th attempt, It crashes when it gets to a tag / command. Could you have a peek and help me fix it once and for all ;)

Cheers and big thanks,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

Hotshot

interesting and i would love to help ya but to honest..I leave to expert such as jim and hellfire to help ya :)

Keep going Clyde :) You are getting there  ;D  You will be overjoy when it is finish :)

hellfire

#42
The reason why your code crashes is that your scrolltext contains a "[" character which is not available in your font.
When you're trying to draw it in update_scroller using draw_gfx_buffer, the data in "scroll->font->frame[ (int)frame ]" is not properly initialized.
I'd suggest to create enough space for all possible characters and initialize the unused ones to an empty "gfx_buffer".

This bug was rather easy to find:
Just build as "debug" and run with debugger (F5).
It drops out in draw_gfx_buffer where "srce" points to some odd adress and its' content is garbage.
In the call stack you can see that draw_gfx_buffer was called from update_scroller where "scroll->message[letter_pos]" is '['.
Without the debugger you can spend hours to find such simple bugs. You should really try it!

Another, more general, thing is you shouldn't do things like that:

screen_buffer= graphics("bitMap scRo77eR TAgS", "", 640,480);
...
gfx_buffer *graphics( char *title, char *title2, int wwidth, int height )
{
  if (title2=="") title2="would you prefer full screen dude?";

You're comparing two char* which are adresses to some location in memory (so they're just numbers).
As the compiler is clever enough to create only a single string when it occurs multiple times, your two occurrences of "" actually point to the same adress in memory - so this code works but that's merely accidental :)

If you want to handle empty strings use 0:
screen_buffer= graphics("bitMap scRo77eR TAgS", 0, 640,480);

gfx_buffer *graphics( char *title, char *title2, int wwidth, int height )
{
  if (title2==0) title2="would you prefer full screen dude?";


Challenge Trophies Won:

Clyde

#43
thanks hellfire :)
wasnt aware of the 0. I also forgot about checking against the total frames.

the tag detection / scroller isnt working as intended; I tried it with different symbols (pause), and it still displayed that in the message. so will need to revisit a new one of this in the future.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won: