![]() |
| | #1 |
| Funniest man in this seat Join Date: Mar 2002
Posts: 801
| Debug Assertion Failed The expression is: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) My program has the following classes: Code:
class zone;
class waypoints
{
private:
int *w_coordinates;
int number_of_w_squares;
zone *zone1;
zone *zone2;
public:
void set_w_coordinates(int pos_x, int pos_y, int a);
void setup(int num_squares, zone &a, zone &b);
zone* GetZone1();
zone* GetZone2();
int GetCoordinate0();
int GetCoordinate1();
~waypoints();
}w_1,w_2,w_3,w_4;
void waypoints::setup(int num_squares, zone &a, zone &b)
{
number_of_w_squares = num_squares;
w_coordinates = new int[num_squares];
zone1 = &a;
zone2 = &b;
}
void waypoints::set_w_coordinates(int x, int y, int b)
{
b = b*2;
w_coordinates[b] = x;
w_coordinates[b+1] = y;
}
waypoints::~waypoints()
{
delete [] w_coordinates;
w_coordinates = NULL;
}
zone* waypoints::GetZone1()
{
return zone1;
}
zone* waypoints::GetZone2()
{
return zone2;
}
int waypoints::GetCoordinate0()
{
return w_coordinates[0];
}
int waypoints::GetCoordinate1()
{
return w_coordinates[1];
}
class zone
{
private:
int number_of_squares, number_of_interfaces;
int *coordinates;
public:
vector <waypoints> interfaces;
void setup(int a, int b);
void set_coordinates(int i, int pos_x, int pos_y);
void set_interfaces(waypoints *a);
bool IsInZone(int x, int y);
int GetSquaresNumber();
int GetSquareCoordinate(int i);
int GetNumberOfInterfaces();
~zone();
}zone_main_corridor,zone_adjoining_corridor_lstairs,zone_adjoining_corridor_rstairs,zone_stairs,zone_offices_corridor;
void zone::setup(int a, int b)
{
number_of_squares = a;
coordinates = new int[a];
number_of_interfaces = b;
}
zone::~zone()
{
delete [] coordinates;
coordinates = NULL;
interfaces.erase(interfaces.begin(),interfaces.end());
}
void zone::set_coordinates(int i, int pos_x, int pos_y)
{
coordinates[i] = pos_x;
coordinates[i+1] = pos_y;
}
void zone::set_interfaces(waypoints *a)
{
interfaces.push_back(*a);
}
bool zone::IsInZone(int x, int y)
{
for (int i=0; i<number_of_squares; i++)
{
if (coordinates[i*2] == x && coordinates[(i*2)+1] == y)
{
return TRUE;
}
}
return FALSE;
}
int zone::GetSquaresNumber()
{
return number_of_squares;
}
int zone::GetSquareCoordinate(int i)
{
return coordinates[i];
}
int zone::GetNumberOfInterfaces()
{
return number_of_interfaces;
}
Code: zone_main_corridor.set_interfaces(&w_1); zone_adjoining_corridor_lstairs.set_interfaces(&w_1); zone_adjoining_corridor_lstairs.set_interfaces(&w_2); zone_stairs.set_interfaces(&w_2); zone_stairs.set_interfaces(&w_3); zone_adjoining_corridor_rstairs.set_interfaces(&w_3); zone_adjoining_corridor_rstairs.set_interfaces(&w_4); zone_offices_corridor.set_interfaces(&w_4); Last edited by minesweeper; 12-11-2002 at 11:06 AM. |
| minesweeper is offline | |
| | #2 |
| PC Fixer-Upper Join Date: May 2002
Posts: 2,001
| this is usually the error that means you are calling delete on a variable that wasn't allocated with new...as far as i can tell there is no calls to new in your program. If it uses new, then delete, if not, do nothing. If that's not the problem then let me know.
__________________ PHP and XML Let's talk about SAX |
| Waldo2k2 is offline | |
| | #3 |
| Funniest man in this seat Join Date: Mar 2002
Posts: 801
| After some more investigating it would seem that the problem occurs when the destructor is called on the zones. However I don't know any more than this because when I use the debugger and try and step into the destructor it gives me the error message. |
| minesweeper is offline | |
| | #4 |
| PC Fixer-Upper Join Date: May 2002
Posts: 2,001
| Are you dull or something?? did you not read what i posted earlier?? heres your problem: you're creating this pointer: int * w_coordinates; then you call delete [] on it theres 2 problems with this, first of all, you didn't allocate memory with it with new, so don't call delete! second, you're calling delete array, and even if you had used new on that int, it wouldn't be an array. So do as i say and take out your calls to delete.
__________________ PHP and XML Let's talk about SAX |
| Waldo2k2 is offline | |
| | #5 |
| Funniest man in this seat Join Date: Mar 2002
Posts: 801
| But does this line not mean it has to be deallocated via delete []? Code: w_coordinates = new int[num_squares]; |
| minesweeper is offline | |
| | #6 |
| PC Fixer-Upper Join Date: May 2002
Posts: 2,001
| ah, didn't see that before...but that error does happen when you delete a pointer that wasn't allocated..... try using new when you declare it, not later...may help, i don't know what to do without the full source
__________________ PHP and XML Let's talk about SAX |
| Waldo2k2 is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Debug Assertion Failed! | IndioDoido | C Programming | 31 | 03-25-2008 11:07 AM |
| debug assertion failed! | chintugavali | C++ Programming | 5 | 12-21-2007 04:05 AM |
| Visual Studio 2005 Debug Assertion Failed | natmas | C++ Programming | 7 | 07-17-2007 04:28 PM |
| debug assertion failed ! | blue_gene | C++ Programming | 2 | 05-09-2004 11:23 AM |
| debug assertion failed?!? | ichijoji | C++ Programming | 3 | 08-30-2003 03:23 PM |