Project: SWT
Bug 176792 [OLE] org.eclipse.swt.internal.ole.win32.ComObject misbehavior in multithreaded application
Reported: 2007-03-09 03:25:55 | Status: resolved fixed

org.eclipse.swt.internal.ole.win32.ComObject constructor accesses to Callbacks and ObjectMap static fields. In multithreaded applications this sometimes leads to org.eclipse.swt.SWTError exceptions with message "No more callbacks". Solution Enclose constructor code in synchronized block public COMObject(int[] argCounts) { int[] callbackAddresses = new int[argCounts.length]; synchronized (Callbacks) { //!!! added line for (int i = 0, length = argCounts.length; i < length; i++){ if ((Callbacks[i][argCounts[i]]) == null) { Callbacks[i][argCounts[i]] = new Callback(this.getClass(), "callback"+i, argCounts[i] + 1, true, COM.E_FAIL); //$NON-NLS-1$ if (Callbacks[i][argCounts[i]].getAddress() == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS); } callbackAddresses[i] = Callbacks[i][argCounts[i]].getAddress(); } int pVtable = OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, 4 * argCounts.length); COM.MoveMemory(pVtable, callbackAddresses, 4 * argCounts.length); ppVtable = OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, 4); COM.MoveMemory(ppVtable, new int[] {pVtable}, 4); ObjectMap.put(new Integer(ppVtable), this); } //!!! added line }

Files changed in fix:
bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/internal/ole/win32/COMObject.java