# Why would this fail?

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

## Recommended Posts

I am working on developing code to write text to the screen using C++ and DirectX11, and in the code where the text can be changed, I'm getting an error. The error says

Windows has triggered a breakpoint in ZLib.exe.
This may be due to a corruption of the heap, which indicates a bug in ZLib.exe or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while ZLib.exe has focus.
The output window may have more diagnostic information.
[/quote]
I don't see anything extra in the output window, other than "[font=Consolas][size=1][font=Consolas][size=1][size=2]Critical error detected c0000374"[/font][/font]

Using breakpoints, I've narrowed down the line that causes the error to this.
 int* temp = new int[new_len]; 
I've also checked the value of new_len in debug mode, to make sure that wasn't the problem, and it is an int variable equal to 11 when it hits this spot. I didn't post all the code, as I can't see why this would fail regardless, but I can if needed. Can anyone help me figure out what's going on?

##### Share on other sites
You probably have heap corruption. Some previous pointer access or buffer overrun has trashed bookkeeping memory used by the heap. This can be due to writing to deleted memory, writing past the end of a buffer or similar problems.

##### Share on other sites
Thanks for quick response!
Is there any easier way to track that down than to follow every step of the program, manually tracking those items?

##### Share on other sites
In tightening up your memory management it might be helpful to add this line at the start of main(), if you haven't already...it will alert you of leaks and potentially where they are, which might also lead to discovering where the heap is getting corrupted.

[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]#if[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] [/font][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]defined[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"](DEBUG) | [/font][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]defined[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"](_DEBUG)[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"] _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );[/font][/font]
[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]#endif[/font][/font][/font]

##### Share on other sites
Depending on your compiler, it may have heap debugging facilities. For example, the code sanchopan posted is MSVC specific. On Windows you can also use Application Verifier to debug some kinds of heap usage errors such as buffer overruns.

##### Share on other sites
Thanks for the help! I downloaded the Application Verifier, and although the results from it didn't help me to find the problem, I ended up finding it by manually following each step in the program. It was indeed due to writing to memory outside the array size, and now it's working great!

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 11
• 9
• 24
• 44