c++arraysruntime-errorheap-memoryvisual-studio-2022

"A breakpoint instruction (__debugbreak() statement or a similar call) was executed in Main.exe", but there is no error?


I have an infinite loop that breaks if user exits out of the main window. I have the following code running in the loop:

unsigned int* renderableShapeIndices = new unsigned int[aNumberCreatedAtRuntime];
// Do something
delete[] renderableShapeIndices;

Then the following happens a couple of loop iterations and cease to happen after the first iteration:

1st breakpoint:
A breakpoint instruction (__debugbreak() statement or a similar call) was executed in Main.exe.

2nd breakpoint:
Unhandled exception at 0x00007FF8C3B8C729 (ntdll.dll) in InTimeEngine2D.exe: 0xC0000374: A heap has been corrupted (parameters: 0x00007FF8C3BF7780).

Has anyone else gone through similar issues? I have no idea what is going on.

Another interesting factor about this is that it only happens in debug mode. It does not happen in release mode.


Solution

  • The answer to the problem is in the comment section of the question.

    Apparently, if one attempts to write to an array outside of its bounds, it will, but it ends up overwriting data of other places in the code, causing bugs in other parts of the program, even if these two parts of the program are unrelated. In my case, they were completely unrelated.