Author Topic: [C++] Bitmap Scroller: Strings And Things.  (Read 19748 times)

0 Members and 1 Guest are viewing this topic.

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: [C++] Bitmap Scroller: Strings And Things.
« Reply #40 on: May 25, 2010 »
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:

Offline Hotshot

  • DBF Aficionado
  • ******
  • Posts: 2114
  • Karma: 91
    • View Profile
Re: [C++] Bitmap Scroller: Strings And Things.
« Reply #41 on: May 25, 2010 »
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 :)

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: [C++] Bitmap Scroller: Strings And Things.
« Reply #42 on: May 26, 2010 »
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:
Code: [Select]
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:
Code: [Select]
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?";

« Last Edit: May 26, 2010 by hellfire »
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: [C++] Bitmap Scroller: Strings And Things.
« Reply #43 on: May 26, 2010 »
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.
« Last Edit: May 26, 2010 by Clyde »
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won: