EVC assert failed debugging method

Source: Internet
Author: User

Recently, I have encountered assert failed errors, which will only be available under Debug. Based on the pop-up dialog box, find the corresponding source file and find the corresponding assert, for example, wingdi. cpp and line1194.

 
Bool cgdiobject: attach (hgdiobj hobject) {assert (m_hobject = NULL); // only attach once, detach on destroyif (hobject = NULL) return false; chandlemap * pmap = afxmaphgdiobj (true); // create map if not existassert (pmap! = NULL); pmap-> setpermanent (m_hobject = hobject, this); Return true ;}

The first assert is row 1194.

Locate the problem and set a breakpoint here. When an error occurs, locate the problem source by checking the stack.

There was a reason at the beginning. This is not representative. For details, see:

Http://topic.csdn.net/u/20121001/23/bda454b2-7997-4fbe-b888-047cd69077be.html? Seed = 2025379092 & R = 79807886 # r_79807886

Later, another reason was cfont's. After the create font was created, it was not deleted, and it was created in onpaint. Therefore, when the window is repainted, it will call the create operation, the above attach (You can use call stack to find out who called this function. You can right-click call stack on memory to call it up.), And the first assert thinks that the first time should be null, and I did not delete the font, so it is not null, so assert appears
Failed.

In fact, in the final analysis, the operation is not standardized. If you want to be lazy, you will not be able to create it. After you select the font for the DC, you need to select the original font from the DC. If the DC is selected and the font is deleted, it is clearly stated in msdn that you are lazy, which makes debugging so hard !!!

When you finish withCfontObject created by
CreatepointfontMethod, first select the font out of the device context, then deleteCfontObject.

 
M_fontb.createpointfont (250, _ T ("Arial"), null );... Cfont * def_font = Dc. SelectObject (& m_fontm );... DC. SelectObject (def_font );

In addition, the pointer must be passed during the SELECT statement. You did not pay attention to it at the beginning.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.