Strange error in allocation with new operator

Started by
2 comments, last by ControlDenied 19 years, 6 months ago
Hi, I have a little struct QSort

struct QSort
{
	sID    ID;
	double SimilarityValue;
};

// sID is also another little struct

struct sID
{
	int m_ClassID;
	int m_ModelID;
};

and in a function I allocate memory with the command: QSort *Similarities = new QSort[Database.m_NumModels]; The program stops in this command and the problem is that (when debugging) it throws the following message: User breakpoint called from code at 0x77f6f570 It then shows the dissasembly window and when I proceed step by step, it requires the path for DBGHOOK.C which I cannot find anywhere. If I run the program it throws an unhandled exception in DBGHEAP.C at this point _ASSERTE(_CrtIsValidHeapPointer(pUserData)); Database.m_NumModels is an integer which I have ensured while debugging that has the right value. Does anybody know any possible reason for this to happen? I cannot think anything, everything seems to me correct. Thanks for any help!
Advertisement
My guess is that something you've done before this point, but very recently before it, most likely, has corrupted the heap in some way or another. Check the code that runs before this line carefully. Look for deletes that might be deleting improper pointers, check for writing beyond the bounds of memory, make sure that you use delete [] when deleting arrays, etc.
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
Ok, that seems realy strange and I am not shure, but I would try a constant instead of Database.m_NumModels.
If that works, then Database is perhaps not instanciated when refering to Database.m_NumModels.

Check all your Pointers if they are refering to an instanciated object when needed, because _ASSERTE(_CrtIsValidHeapPointer(pUserData));
seems to have a problem with pUserData (because _CrtIsValidHeapPointer() retruns false).

You will find it sooner or later, good luck :)

-Constantin
I've just found it, I tried a whole day before posting in the forum and as usually it was something really silly, I deleted somewhere memory and used the array without reallocating

Thanks anyway for the interest!

This topic is closed to new replies.

Advertisement