# Strange error in allocation with new operator

This topic is 5409 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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!

##### Share on other sites
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.

##### Share on other sites
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

##### Share on other sites
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!

• 21
• 13
• 9
• 17
• 13