Jump to content

  • Log In with Google      Sign In   
  • Create Account

Why would this fail?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 trick   Members   -  Reputation: 139

Like
0Likes
Like

Posted 03 March 2012 - 07:42 PM

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.

I don't see anything extra in the output window, other than "Critical error detected c0000374"

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?

Sponsor:

#2 SiCrane   Moderators   -  Reputation: 9598

Like
0Likes
Like

Posted 03 March 2012 - 07:44 PM

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.

#3 trick   Members   -  Reputation: 139

Like
0Likes
Like

Posted 03 March 2012 - 07:50 PM

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?

#4 sanchopan   Members   -  Reputation: 109

Like
0Likes
Like

Posted 04 March 2012 - 01:56 AM

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.

#if defined(DEBUG) | defined(_DEBUG)
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif

#5 SiCrane   Moderators   -  Reputation: 9598

Like
1Likes
Like

Posted 04 March 2012 - 10:37 AM

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.

#6 trick   Members   -  Reputation: 139

Like
0Likes
Like

Posted 05 March 2012 - 08:23 PM

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!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS