Help with Allegro

I am trying to make pong with allegro and c++. As of right now everything is going good but I came upon a problem. I am trying to create a score counter on the screen as you play. I put 10 different strings of the numbers 0-9. Then I put text out to the screen as the array and inside the actual array number I put a get function from another class. It crashes on me everytime I try to play. Someone please help.

1
2
3
4
5
6
7
8
9
10
11
12
    score[9] = "0";
    score[8] = "1";
    score[7] = "2";
    score[6] = "3";
    score[5] = "4";
    score[4] = "5";
    score[3] = "6";
    score[2] = "7";
    score[1] = "8";
    score[0] = "9";

  textout_ex(Buffer, TitleFont, score[collision.getPlayerLives()].c_str(), 50, 60, makecol(255, 255, 255), -1);
Are you sure that you defined score with size of 10?
On a side note, wouldn't it make more sense if you had score[0] = "0", and score[9] = "9" ? :)

Try using debugger and see exactly where program crashes. Sometimes crash in your program comes from different point then expected.
Yea but I have the lives starting at 10 and it subtracts every time it goes past the paddle. Yes I defined it with 10.
See it builds perfectly fine, it just crashes. i have no idea why.
I did the debugger, it just had one problem and it was with alleg42.dll. What would I do next?
closed account (j3Rz8vqX)
I'm sure MatthewRock is asking you to step into your programming and walk it till it crashes; seriously debugging it, not just running the debugger.
VB and codeblocks both can use the stepin/stepout/stepover feature to walk through debug.

As for your code, we can see that you have an array named score that consists of size 10 with string values 0-9; which works fine, it's surely something else.

This portion of the code isn't enough to thoroughly debug your problem.

When does it crash? During allegro initialization? main loop? event loop?
computation process? output process?

Your textout_ex makes us assume its duing output.
Here is the function of allegros textout_ex:
https://www.allegro.cc/manual/4/api/text-output/textout_ex

---Debugging - Things to Consider---
Possibly your score index is out of bounds?
Score has a size of 10, so its maximum index should be 9.
What's your initial player's life index integer (counter)?

What is the value of "collision.getPlayerLives()"?
In your case, it must be less than 10 and greater than -1.

Insert checkpoints (cout if on console) to see how far your program is actually completing. Are the values of variables/pointers what you want them to be before the crash?

when it crashes what kind of error do you receive? possibly segmentation fault?

All else fails, debug, debug, debug or provide more information.
Comment out functions narrow your errors down.

Having no errors and crashing is worst than having errors and crashing.
That usually means logic flaw or lib bugs.
Last edited on
Topic archived. No new replies allowed.