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.