Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

WxWidgets lesson 16 Analysis of the crash caused by the failure of wxTimer to call stop

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

scene

When calling wxTimer function, if the current window is closed, the above problem will occur: 0xC000005: Access collision occurs when reading position 0xFEEEFF06

description

Trace the details of the call stack, the code crash point points to IMPLEMENT_APP(CTestApp)

Call stack points to:

wxEntry(int &,wchar_t * *) Unknown

wxEntry(struct HINSTANCE__ *,struct HINSTANCE__ *,char *,int) Unknown

> WinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, char * __formal, int nCmdShow) Line 4 C++

__tmainCRTStartup() line 528 C

experience

If this information is based solely on it, it is obviously of no practical significance, leading to the following points: When a program crash occurs, you need to continuously trace back from the latest function call to WinMain from the current stack information (HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, char * __formal, int nCmdShow) The pointer type of line 4 C++ is white, and on the list of call stacks, there are other information, especially the content pointed to by the pointer at the top of the call stack: wxEvtHandler:: SafelyProcessEvent(class wxEvent &) unknown, after continuous backtracking, only to know that wxTimerImpl error occurred, obviously this is a timer, and in the program did use the timer, now has locked the target, analysis of the problem will not be too difficult. The problem was not analyzed before, that is, the call stack was not analyzed one by one, and the system call was not understood. The key is which user calls will trigger the system call and cause the problem.

trace call stack

wxEvtHandler::SafelyProcessEvent(class wxEvent &) Unknown

wxTimerImpl::SendEvent(void) Unknown

wxTimerWndProc(struct HWND__ *,unsigned int,unsigned int,long) Unknown

This means that there is a problem when the timer processes messages. At this time, the window is closed. The instance pointer of the timer should have been destroyed. At this time, the timer should not receive any messages. However, from the call stack, the timer continues to process messages, resulting in the problem.

view code

Declaration: wxTimer *m_timer;

m_timer = new wxTimer(this, TIMER_ID);

Start timer: m_timer->Start(10);

conclusion

There is a problem here, there is no stop timer, but even if it does not stop, what is the ultimate cause of this? Of course, this problem is solved by calling m_timer->Stop(), to stop the timer before closing the window

extended

class WXDLLIMPEXP_BASE wxTimer : public wxEvtHandler

class WXDLLIMPEXP_BASE wxEvtHandler : public wxObject

, public wxTrackable

See the timer inheritance relationship from above

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report