![]() |
Changing text in Statusbar pane from timer event |
Post Reply ![]() |
Author | |
mitcheljh ![]() Groupie ![]() Joined: 20 July 2008 Location: United States Status: Offline Points: 35 |
![]() ![]() ![]() ![]() ![]() Posted: 20 March 2009 at 6:48am |
Hi,
I have a timer (WM_TIMER) which triggers the changing of text in a statusbar pane at regular intervals (eg 1 second). I'm noticing that the application crashes intermittently, not when setting the text, but when retrieving the text while the statusbar is being redrawn. Sometimes the crash occurs minutes after starting the app, sometimes much longer. So far, I'm only noticing this issue in the debug build. After the crash, the debugger leaves me at the following line in xtpstatusbar.cpp, and the variable m_strText always contains the correct current text that's displayed in the pane: CString CXTPStatusBarPane::GetText() const { return m_strText; } Below is the stack trace which leads up to the crash:
I'm wondering if this could be a threading issue, and if there's any workaround to the problem. Thanks! |
|
![]() |
|
znakeeye ![]() Senior Member ![]() ![]() Joined: 26 July 2006 Status: Offline Points: 1672 |
![]() ![]() ![]() ![]() ![]() |
Are you running Vista? I had a similar crash (with a popup-menu) which only occurred in Vista.
|
|
PokerMemento - http://www.pokermemento.com/
|
|
![]() |
|
mitcheljh ![]() Groupie ![]() Joined: 20 July 2008 Location: United States Status: Offline Points: 35 |
![]() ![]() ![]() ![]() ![]() |
No, I'm running xp.
So far, I'm only seeing the issue in the debug build. Also, it mainly happens when I'm working in another application. When the application containing the status bar that get's updated has focus, the crash doesn't seem to occur. It could be that I just haven't witnessed it occurring when it has the focus, though. |
|
![]() |
|
Oleg ![]() Admin Group ![]() Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
![]() ![]() ![]() ![]() ![]() |
Hi,
How you set text ?
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
![]() |
|
mitcheljh ![]() Groupie ![]() Joined: 20 July 2008 Location: United States Status: Offline Points: 35 |
![]() ![]() ![]() ![]() ![]() |
I use...
CXTPStatusBarPane* pPane = pStatusBar->FindPane(myPane); assert(pPane); pPane->SetText(myText.c_str()); .. where myText is a std::string. |
|
![]() |
|
Smucker ![]() Senior Member ![]() ![]() Joined: 02 February 2008 Status: Offline Points: 156 |
![]() ![]() ![]() ![]() ![]() |
Are you setting pane text from a separate thread? If so, the setting of the pane's CString may be occurring simultaneously with its use by another thread. When the crash occurs, check the other threads to see if CXTPStatusBarPane::SetText is on the stack.
I usually concentrate all the UI in the main thread, and post messages from other threads for updates, and use synchronization for any objects shared between threads. |
|
Product: Xtreme Toolkit Pro version 13.2 (Unicode, static build)
Platform: Windows 200x/XP/Vista/Win7 (32/64 bit) Language: Visual C++ 9.0 (Studio 2008) |
|
![]() |
|
mitcheljh ![]() Groupie ![]() Joined: 20 July 2008 Location: United States Status: Offline Points: 35 |
![]() ![]() ![]() ![]() ![]() |
Thanks for the suggestion and info, Phillip. The timer I'm using can be used either synchronously or asynchronously, and I've been using it asynchronously. I just changed it to work synchronously (with the main UI thread) and the crash is still occuring.
I think you may be correct about the issue being related to the threads though. If the pane is redrawn in a separate thread (is this true, Oleg?), it may be trying to redraw the pane at the same time I'm updating the text in that pane. What is puzzling is that the issue only seems to be occuring in debug mode. I haven't had a crash (yet) in the release build. |
|
![]() |
|
mitcheljh ![]() Groupie ![]() Joined: 20 July 2008 Location: United States Status: Offline Points: 35 |
![]() ![]() ![]() ![]() ![]() |
UPDATE:
It seems I missed another part of my code where I was setting the timer asynchronously. I changed this so that it is now using the timer synchronously, and so far, I haven't had any crashes. So, it looks like this may have been the problem after all. Thanks Phillip, and also Oleg and znakeeye for looking into this. I'll update this message thread after a couple of days of testing, to inform everyone if setting the timer to work synchronously has indeed fixed the issue. |
|
![]() |
|
Smucker ![]() Senior Member ![]() ![]() Joined: 02 February 2008 Status: Offline Points: 156 |
![]() ![]() ![]() ![]() ![]() |
If WM_TIMER (and the call to SetText) are in a different thread than the one that paints the status pane (and calls GetText), I think you have a race condition in CString handling. Debug code takes more cycles so is sometimes more likely to cause the issue. I guess it could also include non-thread-safe code not in the release compile, but that would be weird. (SetTimer() is never asynchronous; supplying a routine simply automates calling the TimerProc from the default window proc, rather than having to handle WM_TIMER.)
Your stack trace above is from the drawing thread; check your other threads' stacks for calls to CXTPStatusBarPane methods. Also, double-click on the GetText() line and examine this->m_strText. Also, what exception is being reported? Another idea: change your timer to 10 to 50 ms and see if you can get it to crash quicker, and maybe in release mode. I assume you have at least a dual-core system; single-core systems hide (or make much rarer) a lot of multithreading issues. |
|
Product: Xtreme Toolkit Pro version 13.2 (Unicode, static build)
Platform: Windows 200x/XP/Vista/Win7 (32/64 bit) Language: Visual C++ 9.0 (Studio 2008) |
|
![]() |
|
mitcheljh ![]() Groupie ![]() Joined: 20 July 2008 Location: United States Status: Offline Points: 35 |
![]() ![]() ![]() ![]() ![]() |
Thanks for the further info, Phillip.
It looks like this was indeed the issue (using an asynchronous timer). Trying your debugging suggestions, pointed the issue as being a threading issue. The timer I'm using is a 3rd party high accuracy timer, and it can be ran either synchronously or asynchronously. After changing all instances of it to run synchronously, all the crashes have stopped. I tried decreasing the interval time as you suggested and running synchronously, and still no crashes. Switching the 3rd party to synchronous mode won't affect the accuracy of the timer, but may slightly affect the accuracy when the UI thread receives the regular messages, which is OK for my purposes. Thanks again for the info and suggestions. |
|
![]() |
|
Smucker ![]() Senior Member ![]() ![]() Joined: 02 February 2008 Status: Offline Points: 156 |
![]() ![]() ![]() ![]() ![]() |
Sorry for going on about threads, I thought it was the simple SetTimer since you were only using for updating.
APCs can cause reentrancy problems that are very similar to thread issues. Glad you got it sorted out! |
|
Product: Xtreme Toolkit Pro version 13.2 (Unicode, static build)
Platform: Windows 200x/XP/Vista/Win7 (32/64 bit) Language: Visual C++ 9.0 (Studio 2008) |
|
![]() |
Post Reply ![]() |
|
Tweet
|
Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |