SetBackground UnRef causing exception
Re: SetBackground UnRef causing exception
GDI handles can also leak outside obvious painting code, e.g. allocating wxFont, wxBitmap, wxIcon etc. to pass it to a control....
-
- Earned a small fee
- Posts: 10
- Joined: Thu Sep 07, 2017 7:59 am
Re: SetBackground UnRef causing exception
What do you mean with connected?doublemax wrote:I think it's safe to say that there is no memory leak in that paint event code. Also, the number of handles seems almost constant after the window has been shown once. Just to be sure: How is the paint event handler connected?
We just overwrote the wxPanel onPaint() method:
Code: Select all
class SettingsGridPanel : public wxPanel
Yea, our application has one small window for main settings, a button to open an advanced settings dialog and a button to start the test.doublemax wrote:I assume the settings window is opened above the main window? Does that have any custom paint code? Showing and hiding the settings window will also cause a paint event in the underlying window. Maybe the problem lies there. If yes, you should also see the problem if you just move a window from another application over your main window, so that lots of paint events are generated.
The test progress is shown in another two windows, one dialog with a progress bar and a label telling the current test step.
The second window shows test logs and further test details.
I tried as you told me but no paint event entered the onPaint() code i previously posted here.
When I resize the windows a onPaint() event reaches my code.
-
- Earned a small fee
- Posts: 10
- Joined: Thu Sep 07, 2017 7:59 am
Re: SetBackground UnRef causing exception
Thanks, but I already checked our usages of wxFont, wxBitmap, wxIcon etc. and did not find any issues.PB wrote:GDI handles can also leak outside obvious painting code, e.g. allocating wxFont, wxBitmap, wxIcon etc. to pass it to a control....
- eranon
- Can't get richer than this
- Posts: 867
- Joined: Sun May 13, 2012 11:42 pm
- Location: France
- Contact:
Re: SetBackground UnRef causing exception
Did you try to do a dynamic code analysis through tools like BoundsChecker, Dr. Memory, Purify... https://en.wikipedia.org/wiki/Dynamic_program_analysis?
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
-
- Earned a small fee
- Posts: 10
- Joined: Thu Sep 07, 2017 7:59 am
Re: SetBackground UnRef causing exception
Hey,eranon wrote:Did you try to do a dynamic code analysis through tools like BoundsChecker, Dr. Memory, Purify... https://en.wikipedia.org/wiki/Dynamic_program_analysis?
we already use Dr. Memory and I have also checked the reported leaks, but I am not able to identify the source.
Maybe you can help me:
This one appears on application start
Code: Select all
Error #1: GDI USAGE ERROR: DC 0xffffffffc6011cf1 that contains selected object being deleted
system call NtGdiDeleteObjectApp
<system call>
GDI32.dll!GetRandomRgn
??:0
wxDC::~wxDC
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\msw\dc.cpp(314):
wxNotebook::OnPaint
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\msw\notebook.cpp(957):
wxEvtHandler::ProcessEventIfMatches
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\common\event.cpp(1239):
wxEventHashTable::HandleEvent
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\common\event.cpp(907):
wxRegion::~wxRegion
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\msw\region.cpp(144):
wxEvtHandler::ProcessEvent
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\common\event.cpp(1301):
wxWindow::HandlePaint
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\msw\window.cpp(4607):
wxWindow::MSWWindowProc
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\msw\window.cpp(2747):
UxTheme.dll!?
??:0
UxTheme.dll!?
??:0
UxTheme.dll!?
??:0
wxWndProc
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\msw\window.cpp(2618):
USER32.dll!TranslateMessageEx
??:0
USER32.dll!SetWindowTextW
??:0
USER32.dll!IsDialogMessageW
??:0
ntdll.dll!KiUserCallbackDispatcher
??:0
wxWindow::MSWProcessMessage
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\msw\window.cpp(2407):
wxFrame::MSWDoTranslateMessage
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\msw\frame.cpp(825):
Note: DC was allocated here:
system call NtGdiCreateCompatibleDC
<system call>
GDI32.dll!CreateCompatibleDC
??:0
wxMemoryDC::CreateCompatible
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\msw\dcmemory.cpp(74):
wxNotebook::OnPaint
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\msw\notebook.cpp(927):
wxEvtHandler::ProcessEventIfMatches
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\common\event.cpp(1239):
wxEventHashTable::HandleEvent
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\common\event.cpp(907):
wxRegion::~wxRegion
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\msw\region.cpp(144):
wxEvtHandler::ProcessEvent
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\common\event.cpp(1301):
wxWindow::HandlePaint
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\msw\window.cpp(4607):
wxWindow::MSWWindowProc
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\msw\window.cpp(2747):
UxTheme.dll!?
??:0
UxTheme.dll!?
??:0
UxTheme.dll!?
??:0
wxWndProc
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\msw\window.cpp(2618):
USER32.dll!TranslateMessageEx
??:0
USER32.dll!SetWindowTextW
??:0
USER32.dll!IsDialogMessageW
??:0
ntdll.dll!KiUserCallbackDispatcher
??:0
wxWindow::MSWProcessMessage
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\msw\window.cpp(2407):
wxFrame::MSWDoTranslateMessage
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\msw\frame.cpp(825):
Code: Select all
Error #2: GDI USAGE ERROR: DC 0x000000006e01272a that contains selected object being deleted
system call NtUserCallOneParam.RELEASEDC
<system call>
USER32.dll!ReleaseDC
??:0
COMCTL32.dll!Ordinal341
??:0
COMCTL32.dll!Ordinal341
??:0
wxWindow::MSWDefWindowProc
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\msw\window.cpp(2240):
KERNEL32.dll!MultiByteToWideChar
??:0
COMCTL32.dll!Ordinal341
??:0
COMCTL32.dll!Ordinal341
??:0
USER32.dll!TranslateMessageEx
??:0
USER32.dll!CallWindowProcW
??:0
USER32.dll!CallWindowProcA
??:0
wxNotebookWndProc
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\msw\notebook.cpp(915):
USER32.dll!TranslateMessageEx
??:0
USER32.dll!CallWindowProcW
??:0
USER32.dll!CallWindowProcA
??:0
wxWindow::MSWDefWindowProc
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\msw\window.cpp(2240):
wxWindow::MSWWindowProc
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\msw\window.cpp(3427):
UxTheme.dll!DrawThemeParentBackground
??:0
UxTheme.dll!DrawThemeParentBackground
??:0
UxTheme.dll!DrawThemeParentBackground
??:0
Note: DC was allocated here:
system call NtUserGetDC
<system call>
COMCTL32.dll!Ordinal341
??:0
COMCTL32.dll!Ordinal341
??:0
wxWindow::MSWDefWindowProc
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\msw\window.cpp(2240):
KERNEL32.dll!MultiByteToWideChar
??:0
COMCTL32.dll!Ordinal341
??:0
COMCTL32.dll!Ordinal341
??:0
USER32.dll!TranslateMessageEx
??:0
USER32.dll!CallWindowProcW
??:0
USER32.dll!CallWindowProcA
??:0
wxNotebookWndProc
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\msw\notebook.cpp(915):
USER32.dll!TranslateMessageEx
??:0
USER32.dll!CallWindowProcW
??:0
USER32.dll!CallWindowProcA
??:0
wxWindow::MSWDefWindowProc
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\msw\window.cpp(2240):
wxWindow::MSWWindowProc
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\msw\window.cpp(3427):
UxTheme.dll!DrawThemeParentBackground
??:0
UxTheme.dll!DrawThemeParentBackground
??:0
UxTheme.dll!DrawThemeParentBackground
??:0
UxTheme.dll!?
??:0
Code: Select all
Error #4: GDI USAGE ERROR: DC 0xffffffffdd011a7c that contains selected object being deleted
system call NtGdiDeleteObjectApp
<system call>
GDI32.dll!GetRandomRgn
??:0
wxToolTip::Add
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\msw\tooltip.cpp(375):
wxToolTip::SetWindow
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\msw\tooltip.cpp(402):
wxWindowBase::SetToolTip
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\common\wincmn.cpp(1714):
MeasuringSettingPage::MeasuringSettingPage
c:\sspandl\develop_1_5_1\funktionstester\source\fktlibgeneraldataloggertester\datasourceconfigurationpages\measuringsettingpage.cc(21):
SystemTestNBPage::SystemTestNBPage
c:\sspandl\develop_1_5_1\funktionstester\source\funktionstesteruserinterface\systemtestnbpage.cc(66):
wxNotebookWndProc
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\msw\notebook.cpp(915):
USER32.dll!TranslateMessageEx
??:0
USER32.dll!SetScrollInfo
??:0
USER32.dll!GetWindowLongW
??:0
USER32.dll!IsWindow
??:0
USER32.dll!IsServerSideWindow
??:0
USER32.dll!TranslateMessageEx
??:0
USER32.dll!TranslateMessageEx
??:0
USER32.dll!TranslateMessageEx
??:0
USER32.dll!SetWindowTextW
??:0
USER32.dll!GetSystemMenu
??:0
wxWindowBase::InvalidateBestSize
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\common\wincmn.cpp(514):
wxStringData::Unlock
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\include\wx\string.h(243):
Note: DC was allocated here:
system call NtGdiCreateCompatibleDC
<system call>
GDI32.dll!CreateCompatibleDC
??:0
wxToolTip::Add
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\msw\tooltip.cpp(343):
wxToolTip::SetWindow
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\msw\tooltip.cpp(402):
wxWindowBase::SetToolTip
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\common\wincmn.cpp(1714):
MeasuringSettingPage::MeasuringSettingPage
c:\sspandl\develop_1_5_1\funktionstester\source\fktlibgeneraldataloggertester\datasourceconfigurationpages\measuringsettingpage.cc(21):
SystemTestNBPage::SystemTestNBPage
c:\sspandl\develop_1_5_1\funktionstester\source\funktionstesteruserinterface\systemtestnbpage.cc(66):
wxNotebookWndProc
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\msw\notebook.cpp(915):
USER32.dll!TranslateMessageEx
??:0
USER32.dll!SetScrollInfo
??:0
USER32.dll!GetWindowLongW
??:0
USER32.dll!IsWindow
??:0
USER32.dll!IsServerSideWindow
??:0
USER32.dll!TranslateMessageEx
??:0
USER32.dll!TranslateMessageEx
??:0
USER32.dll!TranslateMessageEx
??:0
USER32.dll!SetWindowTextW
??:0
USER32.dll!GetSystemMenu
??:0
wxWindowBase::InvalidateBestSize
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\common\wincmn.cpp(514):
wxStringData::Unlock
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\include\wx\string.h(243):
- eranon
- Can't get richer than this
- Posts: 867
- Joined: Sun May 13, 2012 11:42 pm
- Location: France
- Contact:
Re: SetBackground UnRef causing exception
I'm not used to use Dr. Memory specially, but according to their doc, it's not necessary relevant talking about recent Windows version: http://drmemory.org/docs/page_gdi.html (and in their topics -- at left side of the help pages --, it seems they separate memory leaks and GDI usage errors). So, maybe trying different analysis tools will help to figure out the point(s) of failure by crosscheck...
Last edited by eranon on Mon Sep 18, 2017 9:35 pm, edited 2 times in total.
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
Re: SetBackground UnRef causing exception
wxWidgets event handlers are not implemented by overriding virtual methods. This method can have any name, there must be either a static event table or a Connect() call somewhere.We just overwrote the wxPanel onPaint() method:
Code: Select all
wxNotebook::OnPaint
c:\sspandl\develop_1_5_1\funktionstester\externallibs\wx2017_x64\src\msw\notebook.cpp(927):
Seeing this, it's even possible that this is a bug in wxWidgets which has been fixed many years ago. Have you ever tried to compile your project under wx 3.1.x? Or did you just assume that it's a lot of work?
For a test, disable the paint event handler in SettingsGridPanel and check if the leak still exists. If yes, we've been searching in the wrong spot all the time.
Use the source, Luke!
- eranon
- Can't get richer than this
- Posts: 867
- Joined: Sun May 13, 2012 11:42 pm
- Location: France
- Contact:
Re: SetBackground UnRef causing exception
If it can help determining if the info is relevant or not, running Dr. Memory (1.11) against one of my own apps (launching the program, then exiting immediately), I got "13 total GDI usage errors" whose 12 about wxToolTip and one about wxNotebook:
Done under Windows 7 64-bit with a 32-bit DEBUG build of the app (wx31-based).
Code: Select all
Error #35: GDI USAGE ERROR: DC 0x5f011a41 that contains selected object being deleted
# 0 system call NtGdiDeleteObjectApp
# 1 GDI32.dll!DeleteDC +0xb6 (0x7696596a <GDI32.dll+0x1596a>)
# 2 GDI32.dll!DeleteDC +0x11 (0x769658c5 <GDI32.dll+0x158c5>)
# 3 wxMSWDCImpl::~wxMSWDCImpl [../../src/msw/dc.cpp:512]
# 4 wxMemoryDCImpl::~wxMemoryDCImpl [../../include/wx/msw/dcmemory.h:17]
# 5 wxMemoryDCImpl::~wxMemoryDCImpl [../../include/wx/msw/dcmemory.h:17]
# 6 wxDC::~wxDC [C:/devlibs/wxWidgets-3.1.0/include/wx/dc.h:742]
# 7 wxMemoryDC::~wxMemoryDC [C:/devlibs/wxWidgets-3.1.0/include/wx/dcmemory.h:21]
# 8 wxNotebook::OnPaint [../../src/msw/notebook.cpp:882]
# 9 wxAppConsoleBase::HandleEvent [../../src/common/appbase.cpp:657]
#10 wxAppConsoleBase::CallEventHandler [../../src/common/appbase.cpp:669]
#11 wxEvtHandler::ProcessEventIfMatchesId [../../src/common/event.cpp:1381]
#12 wxEventHashTable::HandleEvent [../../src/common/event.cpp:989]
#13 wxEvtHandler::TryHereOnly [../../src/common/event.cpp:1578]
#14 wxEvtHandler::TryBeforeAndHere [../../include/wx/event.h:3656]
#15 wxEvtHandler::ProcessEventLocally [../../src/common/event.cpp:1511]
#16 wxEvtHandler::ProcessEvent [../../src/common/event.cpp:1484]
#17 wxEvtHandler::SafelyProcessEvent [../../src/common/event.cpp:1602]
#18 wxWindowBase::HandleWindowEvent [../../src/common/wincmn.cpp:1534]
#19 wxWindow::HandlePaint [../../src/msw/window.cpp:4719]
Note: @0:00:59.778 in thread 8248
Note: DC was allocated here:
Note: # 0 system call NtGdiCreateCompatibleDC
Note: # 1 GDI32.dll!CreateCompatibleDC +0xf (0x76965504 <GDI32.dll+0x15504>)
Note: # 2 wxMemoryDCImpl::CreateCompatible [../../src/msw/dcmemory.cpp:90]
Note: # 3 wxMemoryDCImpl::wxMemoryDCImpl [../../src/msw/dcmemory.cpp:45]
Note: # 4 wxNativeDCFactory::CreateMemoryDC [../../src/common/dcbase.cpp:149]
Note: # 5 wxMemoryDC::wxMemoryDC [../../src/common/dcbase.cpp:214]
Note: # 6 wxNotebook::OnPaint [../../src/msw/notebook.cpp:802]
Note: # 7 wxAppConsoleBase::HandleEvent [../../src/common/appbase.cpp:657]
Note: # 8 wxAppConsoleBase::CallEventHandler [../../src/common/appbase.cpp:669]
Note: # 9 wxEvtHandler::ProcessEventIfMatchesId [../../src/common/event.cpp:1381]
Note: #10 wxEventHashTable::HandleEvent [../../src/common/event.cpp:989]
Note: #11 wxEvtHandler::TryHereOnly [../../src/common/event.cpp:1578]
Note: #12 wxEvtHandler::TryBeforeAndHere [../../include/wx/event.h:3656]
Note: #13 wxEvtHandler::ProcessEventLocally [../../src/common/event.cpp:1511]
Note: #14 wxEvtHandler::ProcessEvent [../../src/common/event.cpp:1484]
Note: #15 wxEvtHandler::SafelyProcessEvent [../../src/common/event.cpp:1602]
Note: #16 wxWindowBase::HandleWindowEvent [../../src/common/wincmn.cpp:1534]
Note: #17 wxWindow::HandlePaint [../../src/msw/window.cpp:4719]
Note: #18 wxWindow::MSWHandleMessage [../../src/msw/window.cpp:2810]
Note: #19 wxWindow::MSWWindowProc [../../src/msw/window.cpp:3524]
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
Re: SetBackground UnRef causing exception
Thanks. So it's possible that the errors in the wxNoteBook paint event handler are not relevant after all. This is getting more confusing all the time.eranon wrote:If it can help determining if the info is relevant or not, running Dr. Memory (1.11) against one of my own apps (launching the program, then exiting immediately), I got "13 total GDI usage errors" whose 12 about wxToolTip and one about wxNotebook:
To OP: If you can't provide a sample that demonstrates the issue, i can only recommend to start commenting out parts of your code that deal with GDI objects until you've narrowed down the code location.
If you can't post relevant code publicly, you can also PM me. Maybe we can figure something out.
Use the source, Luke!
-
- Earned a small fee
- Posts: 10
- Joined: Thu Sep 07, 2017 7:59 am
Re: SetBackground UnRef causing exception
Hey, again.
Thanks for your suggestions doublemax and eranon (especially for the Dr. Memory testing).
First your questions:
As said we are testing with some paint events commented out. I´ll give you feedback as soon as possible.
The GDI- and User-Object monitoring is implemented, but since that we did not have a crash, so I still can not say that it is a GDI- User-Object leak.
Thanks for your suggestions doublemax and eranon (especially for the Dr. Memory testing).
First your questions:
yes, but there are too many to show them all hereDo you have any class that derives from wxNotebook?
We tried, but got many linking errors. I think I can remember because of an wxWidgets API change.Have you ever tried to compile your project under wx 3.1.x? Or did you just assume that it's a lot of work?
We did that and testing is still going on. We cant yet say it solved the problem, but the error has not occured yet.For a test, disable the paint event handler in SettingsGridPanel and check if the leak still exists.
We do not know under what circumstances the error happens, so I can not provide a sample.To OP: If you can't provide a sample that demonstrates the issue, i can only recommend to start commenting out parts of your code that deal with GDI objects until you've narrowed down the code location.
As said we are testing with some paint events commented out. I´ll give you feedback as soon as possible.
The GDI- and User-Object monitoring is implemented, but since that we did not have a crash, so I still can not say that it is a GDI- User-Object leak.
Re: SetBackground UnRef causing exception
You said you got an increase of GDI handles when you opened end closed the settings window. Shouldn't the change be visible immediately ?The GDI- and User-Object monitoring is implemented, but since that we did not have a crash, so I still can not say that it is a GDI- User-Object leak.
Use the source, Luke!
-
- Earned a small fee
- Posts: 10
- Joined: Thu Sep 07, 2017 7:59 am
Re: SetBackground UnRef causing exception
Yea, that is true, but that was just a test to check if there is a leak somewhere in general.You said you got an increase of GDI handles when you opened end closed the settings window. Shouldn't the change be visible immediately ?
Our guess is that there might be a leak in the progress panel or our log-output panel, but it only happens sporadically.
There is no leak on short test runs, only on long Test runs (1 hour per test cycle for about a week).
Re: SetBackground UnRef causing exception
I havent used wxWidgets 2.8, so this is just a stab in the dark.
When I looked at your stack trace in the OP, it struck me as being very similar to what you would expect to see when you perform GUI tasks in a function that is called from a thread outside of the GUI context.
And then I saw
This is really just a guess though.
When I looked at your stack trace in the OP, it struck me as being very similar to what you would expect to see when you perform GUI tasks in a function that is called from a thread outside of the GUI context.
And then I saw
Which leads me to think that, potentially, since your onPaint code wasnt properly connected to the event loop, your "this" pointer may lie outside of the GUI context, so you wind up with intermittent exceptions when trying to Ref and UnRef the GUI objects.doublemax wrote:wxWidgets event handlers are not implemented by overriding virtual methods. This method can have any name, there must be either a static event table or a Connect() call somewhere.What do you mean with connected?
We just overwrote the wxPanel onPaint() method:
...
no paint event entered the onPaint() code i previously posted here.
This is really just a guess though.