[RESOLVED] Debug Assertion Failed CWnd::KillTimer(UINT_PTR nIDEvent)
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: [RESOLVED] Debug Assertion Failed CWnd::KillTimer(UINT_PTR nIDEvent)

  1. #1
    Join Date
    Nov 2006
    Location
    Australia
    Posts
    1,569

    [RESOLVED] Debug Assertion Failed CWnd::KillTimer(UINT_PTR nIDEvent)

    Hey.

    I'm getting a failed assertion for this code at the bolded line:
    Code:
    void CMFCDeviceSimulatorDlg::Start_Timer(UINT timer_duration)
    {
    	timer_id = static_cast<UINT>(SetTimer(IDT_TIMER_0, timer_duration, NULL));
    
    	if(timer_id == 0)
    	{
    		throw std::runtime_error("Couldn't set timer.");
    	}
    }
    
    void CMFCDeviceSimulatorDlg::Stop_Timer()
    {
    	if(!KillTimer(timer_id))
    	{
    		throw std::runtime_error("Couldn't kill timer.");
    	}
    	timer_id = 0;
    }
    Code:
    static const UINT TIMER_DURATION = 500;
    	UINT timer_id;
    The assertion fails at this code in afxwin2.inl:
    Code:
    _AFXWIN_INLINE BOOL CWnd::KillTimer(UINT_PTR nIDEvent)
    	{ ASSERT(::IsWindow(m_hWnd)); return ::KillTimer(m_hWnd, nIDEvent); }
    I sort of understand why it's doing it, as I read this.. but I have no idea on how to add the OnDestroy handler. For instance, do I just add the function, or do I have to add stuff to the message map etc.? There's not much information on this on the net...

    Cheers.
    Good judgment is gained from experience. Experience is gained from bad judgment.
    Cosy Little Game | SDL | GM script | VLD | Syntax Hlt | Can you help me with my homework assignment?

  2. #2
    Join Date
    Nov 2006
    Location
    Australia
    Posts
    1,569

    Re: Debug Assertion Failed CWnd::KillTimer(UINT_PTR nIDEvent)

    Oh.. nevermind. I hadn't initialised timer_id to 0 in the constructor and so it was a junk value... :s
    Good judgment is gained from experience. Experience is gained from bad judgment.
    Cosy Little Game | SDL | GM script | VLD | Syntax Hlt | Can you help me with my homework assignment?

  3. #3
    Join Date
    Nov 2003
    Posts
    1,815

    Re: [RESOLVED] Debug Assertion Failed CWnd::KillTimer(UINT_PTR nIDEvent)

    http://msdn.microsoft.com/en-us/library/k6tw900t.aspx
    http://msdn.microsoft.com/en-us/library/sk92a2ws.aspx

    Be sure to call "BaseClass::OnDestroy()".

    If you are calling Stop_Timer() in the destructor, you'll still want to move that to an OnDestroy() handler.

    gg

  4. #4
    Join Date
    Nov 2006
    Location
    Australia
    Posts
    1,569

    Re: [RESOLVED] Debug Assertion Failed CWnd::KillTimer(UINT_PTR nIDEvent)

    Oh cheers Codeplug. You're right, it still gave me that error.. I have two possible paths of execution in the program and I just tried the other one and it gave me the assertion haha.

    I didn't call BaseClass::OnDestroy anywhere and the handler still gets called - why is calling that function necessary?
    Good judgment is gained from experience. Experience is gained from bad judgment.
    Cosy Little Game | SDL | GM script | VLD | Syntax Hlt | Can you help me with my homework assignment?

  5. #5
    Join Date
    Nov 2003
    Posts
    1,815

    Re: [RESOLVED] Debug Assertion Failed CWnd::KillTimer(UINT_PTR nIDEvent)

    When you add ON_WM_DESTROY to your message map, you are (potentially) overriding the the base classes entry to call its OnDestroy(). In this cases, you do your work then call Base::OnDestroy() so the Base can do what it needs to do.

    Not all message *need* to be handled by the base, and sometimes it's up to you if you want the functionality provided by the base. But for OnDestroy(), you need to pass that one along so the bases can do some cleanup.

    gg

  6. #6
    Join Date
    Nov 2006
    Location
    Australia
    Posts
    1,569

    Re: [RESOLVED] Debug Assertion Failed CWnd::KillTimer(UINT_PTR nIDEvent)

    Oh, ok. I ran it without calling Base::OnDestroy and Visual Leak Detector didn't detect any leaks... so I'm curious what clean up you are talking about?
    Good judgment is gained from experience. Experience is gained from bad judgment.
    Cosy Little Game | SDL | GM script | VLD | Syntax Hlt | Can you help me with my homework assignment?

  7. #7
    Join Date
    Nov 2003
    Posts
    1,815

    Re: [RESOLVED] Debug Assertion Failed CWnd::KillTimer(UINT_PTR nIDEvent)

    Just search the MFC source for "::OnDestroy()". Lot's of code to look at. CWnd::OnDestroy() doesn't do much.

    gg

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center