Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
This is a problem I have beating my head against for 6 months. I'm hoping that someone else has encountered this issue and found either a solution or a workaround.

I am using VS 2010 C++ Express to develop W32 apps on a PC running 64-bit Win 7 Home edition. A chronic problem I encounter w/ all such apps is that the release *.exe will INTERMITTENTLY substitute the system font in lieu of the specified font when rendering text using the DrawText function.

The problem never occurs while running the app under Debug in the IDE. The problem manifests only with the release *.exe running in the following environments:

Occasionally running from VS 2010 IDE
More frequently running from a directory on same PC hosting VS 2010.
Still more frequently on another PC running
64-bit Win 7 Professional Edition.
or 32-bit Win 7 Home Edition
or XP w/ SP3
or Win NT

The problem ONLY occurs in a Dialog callback that uses TextOut() to write to its own window. All fonts are created using CreateFontIndirect() referencing a LOGFONT structure.

There appears to be no pattern to occurrences. The problem will manifest only for some (but not all) uses of DrawText () in a single call to the callback.

Sometimes the problem will manifest in the 2nd or 3rd call to the callback. At other times, the problem will not occur until the callback has been called 20 or more times. A single occurrence may manifest on one call to callback followed by multiple callback calls w/o any occurrences. I.e., the issues does not appear to be related to a memory leakage, stack overflow or inadequate heap space.

Solutions I have tried.
(1) Font created one time as a global variable by main WinProc.
vs. Font created one time as a static variable by main WinProc (and passed to callback)
vs. Font created one time as a static variable in callback under WM_INITDIALOG.
vs. Font created/destroyed as a static variable in callback on each all call to callback.
vs. Font created/destroyed as a non-static variable in callback before and following each reference to DrawText (). This config seems to work best.

(2) Tried all combinations of large and small values for stack size and heap size under Linker -> System. Minimum values for each seem to work best.

Can anyone help?
Posted
Updated 10-May-15 17:30pm
v4
Comments
barneyman 11-May-15 0:08am    
sounds like a GDI leak :)

you ARE re-selecting the old font back into the DC before you destroy it?
Member 10946506 11-May-15 22:28pm    
Thank you for your response.
To answer your question, No, I did not have a 2nd SelectObject call immediately preceding the DeleteObject call.
I was not aware that one needed to do so.

Based upon your input, I revised my code to add said item and retested the app on my 64-bit PC running Win 7 Home Premium and on my 64-bit work station running Win 7 Professional.

The problem has not recurred. Because of the intermittent nature of the bug, I hesitate to pronounce this a cure. However, it does appear to be a major step in the right direction.

Thanks for the suggestion.


barneyman 11-May-15 23:33pm    
no problem - i only suggested it because i have some code i wrote with some extremely angry comments about just this sort of behaviour because of DC corruption
Style-7 11-May-15 1:54am    
Need code.
What value in "Project propertes - C/C++ - Code Generation - Runtime Library"?
Richard MacCutchan 11-May-15 3:25am    
Please edit your question and show the code where the problem occurs; we cannot guess what is happening.

1 solution

(comment promoted to answer)

sounds like a GDI leak :)

you ARE re-selecting the old font back into the DC before you destroy it?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900