Jump to content
  • Advertisement
Sign in to follow this  
trick

Why would this fail?

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!