Last Comment Bug 671792 - "ASSERTION: ImmAssociateContextEx failed to restore default IMC"
: "ASSERTION: ImmAssociateContextEx failed to restore default IMC"
Status: RESOLVED FIXED
: testcase
Product: Core
Classification: Components
Component: Widget: Win32 (show other bugs)
: Trunk
: x86_64 Windows 7
: -- normal (vote)
: mozilla9
Assigned To: Brian R. Bondy [:bbondy]
:
: Jim Mathies [:jimm]
Mentors:
Depends on:
Blocks: 594645 622312
  Show dependency treegraph
 
Reported: 2011-07-14 22:47 PDT by Jesse Ruderman
Modified: 2011-08-25 18:37 PDT (History)
4 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
Patch for ASSERTION: ImmAssociateContextEx failed to restore default IMC (969 bytes, patch)
2011-07-19 16:33 PDT, Brian R. Bondy [:bbondy]
neil: review+
Details | Diff | Splinter Review

Description Jesse Ruderman 2011-07-14 22:47:16 PDT
1. In the address bar, enter http://www.squarefree.com/bug662261/x.test
2. Right-click Firefox's taskbar icon and select "close all windows"

Result:

###!!! ASSERTION: ImmAssociateContextEx failed to restore default IMC: 'ret || !nsIMM32Handler::IsIMEAvailable()', file widget/src/windows/nsWindow.cpp, line 8038
Comment 1 Brian R. Bondy [:bbondy] 2011-07-16 22:05:47 PDT
I can reproduce this so I'll take it.
Comment 2 Brian R. Bondy [:bbondy] 2011-07-19 16:33:57 PDT
Created attachment 546938 [details] [diff] [review]
Patch for ASSERTION: ImmAssociateContextEx failed to restore default IMC

The assertion was failing because of a GetLastError() of invalid handle on the Win32 API call to "::ImmAssociateContextEx(mWnd, .._)".
The problem was that we were destroying the window twice.

The call "DispatchStandardEvent(NS_DESTROY);" inside "nsWindow::OnDestroy" was sometimes leading to "nsXULWindow::Destroy" which would in turn call "mWindow->Destroy()" a second time. Where the error happened.
  
We were already checking to make sure we didn't destroy twice with "if (nsnull == mWnd) return NS_OK" in "nsWindow::Destroy()" but this would only check that we finished the WM_DESTROY message, not that we already started the WM_DESTROY message.  

Instead we should check that we have started the WM_DESTROY message to ensure the above situation doens't happen.  This can be done by changing: "if (nsnull == mWnd) return NS_OK" to " if (mOnDestroyCalled)
 return NS_OK;"
Comment 3 Brian R. Bondy [:bbondy] 2011-07-19 16:44:52 PDT
This patch also fixes a different similar error in Bug 622312.
Comment 4 neil@parkwaycc.co.uk 2011-07-27 02:15:00 PDT
Aha, so OnDestroy calls DispatchStandardEvent(NS_DESTROY) which normally does nothing, because something else has been destroyed first. But sometimes it hasn't, in which case nsXULWindow tries to destroy the nsWindow again...
Comment 5 Brian R. Bondy [:bbondy] 2011-07-27 04:46:41 PDT
Right, basically from within the destroy it can lead to another destroy.  We had a check for double destroy but the way we checked it was if the destroy was done, and not if the destroy had already started.
Comment 6 Brian R. Bondy [:bbondy] 2011-08-05 13:47:17 PDT
Comment on attachment 546938 [details] [diff] [review]
Patch for ASSERTION: ImmAssociateContextEx failed to restore default IMC

Going to run through try before checkin?
Comment 7 Brian R. Bondy [:bbondy] 2011-08-25 08:32:53 PDT
pushed to mozilla-inbound.
Comment 8 Ed Morley [:emorley] 2011-08-25 18:37:55 PDT
http://hg.mozilla.org/mozilla-central/rev/72459db22a34

Note You need to log in before you can comment on or make changes to this bug.