Debug assertion failed?

So I'm getting this error in my program. I have no idea what it means, and its a popup error.

Picture of error:
http://www.imageuploads.net/ims/pic.php?u=40605If37K&i=194074

It's a text adventure program, and this only pops up during the battle sequence, and even then, on rare occasions. Line 1891 is int main() so I have no idea what the problem could be.

Thanks
Have you read the Visual C++ documentation on asserts? Have you tried to debug the program properly?
I have. And I'm not sure how to, I click retry, and it takes me to a file called stdthrow.cpp, I've since edited the code, and now nothing is on line 1891, but when I run the program, sometimes I get that same error, telling me there's an error on line 1891.
Does anyone have any kind of ideas on how to fix this?
No - because there seems to be a problem with the link.
Hm. Well that's weird. It was working the other day. Oh well, here's another picture of the error:

http://i30.photobucket.com/albums/c327/TheHolyfork/image_194074bmp.jpg
It is as the error message said:
You are doing something with a std::string and you are passing a bad (NULL) pointer
to a string member function.

I looked at xstring and on my system - and all the functions around line 1891 area are the find_*** functions - for example find_first_of , find_last_of.

Post your code - let's check
My whole code is around 3000 lines. So I'm not so sure that's a good idea. But if you still want me to, I will

Edit: Actually, I realized I know the area that's causing this error, so I'll just post that code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
int Attack(int a){
   
    if(currentPlayer == HUMAN_PLAYER){
       
                do{

					if(Cstats.currentweapon == Table[x].Name){
						Dmgvalue = Table[x].Damage;
						yes = false;
					}else
					{
						x++;
						yes = true;
					}
				}while(yes != false);

                    AttackRoll =  (1 + rand() % (20)) + Cstats.BaseAttk;
               
                    if(AttackRoll >= Mob[m].ArmorClass){
                       
                        Mob[m].Health -= Dmgvalue;
                        cout << "---------------------------------------------------------------" << endl;
                        cout << "YOU USE YOUR " << Cstats.currentweapon << " TO CHOP THAT "<< Mob[m].Name << "'s ARM OFF!!!!" <<endl;
           
						}else{
							cout << "---------------------------------------------------------------" << endl;
							cout << "YOU MISS!!!" <<endl;
						}
                }
      else
                {
                    cout << "The " << Mob[m].Name << " is making an attack!" << endl;
                    Sleep(3000);

                    do{

                        if(Mob[m].Weapon == Table[y].Name){
                            MobDmg = Table[y].Damage;
                            yes = false;
                        }else
                        {
                            y++;
                            yes = true;
                        }
                     }while(yes != false);

                    AttackRoll = 1 + rand() % (20);
               
                    if(AttackRoll >= inventory[0].ArmorClass){
                        Cstats.Health -= MobDmg;
                        cout << "THE " << Mob[m].Name << " CUT YOUR BLOODY HAND OFF" <<endl;
                    }else{
                        cout << "He missed!" << endl;
                    }

                }
                //do we have a winner?
                if(Cstats.Health <1 || Mob[m].Health < 1)
                {
                   
                    if(currentPlayer == HUMAN_PLAYER)
                    {
                        cout<< "You WIN! Congratz!" << endl <<endl;
						if(a==0)
						{
							Cstats.Exp += Mob[m].Exp;
							save();
							cout << "You now have " << Cstats.Exp << " experience points. You have " << reqxp-Cstats.Exp << " experience points left until you level up." << endl;
							if(Cstats.Exp>=reqxp)
							{
								Level();
							}
						}
						else if(a==1)
						{
							cout << "Moving on to next battle." << endl;
							return 1;
						}
						else if(a==2)
						{
							cout << "You've beaten The Arena! Congratulations!" << endl;
							return 2;
						}
                    }
                    else
                    {
                        cout<< "You DIE!" <<endl << endl;
                    }
                }else{
                    currentPlayer = !currentPlayer;
                }
       
       


return 0;
}


It's only appearing when the Mob is attacking, the main else in this code. I've never experienced it in the part where the player attacks, or it displays a victory message, or a defeat message.
Last edited on
For the record - I should have noticed that the image of the error you posted said VC2010.

In my earlier post I said that the string functions in xstring are all about the std::string find*** functions (but I was looking at VC2008)

In msvc 2010 - the function round line 1891 in xstring are string comparison functions.

This looks like a string comparison here -what is Table[y] - is that an char *array ??

if(Mob[m].Weapon == Table[y].Name)
Last edited on
I don't think it is, but I could be wrong. Here's where Table[y] is created:

1
2
3
4
5
6
7
8
9
struct Weapons{
    string Name;
    int Damage;
	int Cost;
	int Stock;
	int Number;
	string Desc;
	int ArBonus;
}Table[50];
Last edited on
Also, I'm getting the error in another part of my code now too, along with this part still. I'm not sure why I'm getting it in this part now either. It's in a part of the code where the user can use an item like a potion to heal. The user can access the item use screen from two areas, when their viewing their inventory, and when the battle sequence is active. I have never experienced the error when accessing the use items function from the battle sequence, yet whenever I access it from the inventory, I always get the error. I have no idea why, both the inventory and battle sequence call the function the same way, and it doesn't take in a variable, so it's not like it's using something it shouldn't be.
Last edited on
guestgulkan is correct, I had this problem yesterday and it was because of the way you are trying to compare two strings.

Try something like:
if( strcmp( Mob[m].Weapon, Table[y].Name ) )
Last edited on
Try something like: *snip*


When comparing std::strings, you use ==, strcmp is for char* (C strings) only.

Is Mob[m].Weapon also a string?
Yes, Mob[m].Weapon is also a string.

1
2
3
4
5
6
7
8
struct Monster{
    int Health;
    string Name;
    string Armor;
    int ArmorClass;
    string Weapon;
	int Exp;
}Mob[100];


Also, I just figured out that the problem IS in the loop. I just had the program output messages before, during and after the loop. Whenever the program breaks with that error, only the messages before and during appear. It seems like my variable "y" is incrementing too much. However, setting it equal to zero before it enters the loop does not solve the error.
Last edited on
Well...I might feel like an idiot after asking this. Especially if this was what was causing the error. But! How possible is it that in the Table[y] array, if I had a certain array spot filled, and then filled it again with new data right after, be the cause of it?

Ex:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Table[11].Name = "Dual Swords";
    Table[11].Desc = "Two swords";
    Table[11].Damage = 8;
    Table[11].ArBonus = 0;

    Table[11].Name = "Spear";
    Table[11].Desc = "A sharp stick";
    Table[11].Damage = 3;
    Table[11].ArBonus = 0;

    Table[11].Name = "Fists";
    Table[11].Desc = "Bare hands";
    Table[11].Damage = 4;
    Table[11].ArBonus = 0; 


Because, I'm not sure how I missed it, or how I even did it, but I had written this in my code. I've been testing my program since I changed it, and have yet to experience the error, but, like I said earlier, it only appears on rare occasions.
But could this have been what was causing the error?
Topic archived. No new replies allowed.