6

i have this game of domino i created using CPP. While playing i'm getting this error:

Unhandled exception at 0x76FF5934 (ntdll.dll) in Domino.exe: 0xC0000374: A heap has been corrupted (parameters: 0x77011378).

Same error but the timing and the place in code it breaks is different, but the code it breaks on is always the same:

Stone* P = new Stone[numP];

This code is found in all sort of places, Stone is a class i created to represent a domino stone.

I have no idea what's wrong, i'm pretty sure it has something to do with memory but i have no idea why this line is causing problems, i'm not expecting you to tell me why it's happening since you can't see the full code but i hope you could try and help me with places to search for.

trincot
  • 317,000
  • 35
  • 244
  • 286
Dorin Haliva
  • 81
  • 1
  • 1
  • 2

2 Answers2

9

Heap corruption is generally not caused by the line of code where it is detected. It is likely that there is another place in your code where memory corruption is occurring which is only being detected when you attempt to allocate your Stone array. Check for buffer overruns and other places where you are writing to dynamically allocated memory.

Qartar
  • 400
  • 1
  • 9
  • That's also what i thought, but it also happens when i declare a all new array and assign the new memory, how can i find what causes the heap corruption than? – Dorin Haliva Apr 13 '15 at 15:46
  • @DorinHaliva heap corruption is one of the hardest errors to track down, and a big reason why people think languages other than C++ are easier. – Mark Ransom Apr 13 '15 at 15:49
  • I would start looking at the Rule Of Three. Perhaps this is the reason for heap corruption: http://stackoverflow.com/questions/4172722/what-is-the-rule-of-three – drescherjm Apr 13 '15 at 15:59
4

Keep in mind that where ever the debugger stops only tells you where the damage was detected, never where the damage was done. So, i would step through your code and find what is going on with your Stone class. Its highly likely that there may be a flaw in your class structure. If the class isnt too big, post it and maybe it can be diagnosed?

Javia1492
  • 862
  • 11
  • 28