2

For our SWT-based application we've got certain different SWT crash reports where SWT crashes with "no more handles" errors. This only happens for very few people and sometimes in a very early stage of launching the application. A typical stacktrace of the very early application state looks like this:

Caused by: org.eclipse.swt.SWTError: No more handles
    at org.eclipse.swt.SWT.error(SWT.java:4467)
    at org.eclipse.swt.SWT.error(SWT.java:4356)
    at org.eclipse.swt.SWT.error(SWT.java:4327)
    at org.eclipse.swt.widgets.Widget.error(Widget.java:476)
    at org.eclipse.swt.widgets.TaskBar.createHandle(TaskBar.java:103)
    at org.eclipse.swt.widgets.TaskBar.<init>(TaskBar.java:96)
    at org.eclipse.swt.widgets.Display.getSystemTaskBar(Display.java:2567)
    ...

We already have tested our application and under normal conditions it does not leak any resources (fonts, colors, images, GCs, ...), the values in the Windows Task Manager (Handles, USER Objects, GDI Objects, ...) are only in the top third, but often not the top most ones.

What reasons could cause such problems - could it be a machine with a lot of applications running, other possibly debugged applications leak massive resources, what else? What information, e.g. output of "tasklist.exe" I need to request from the users to get a clue for a possible reason?

Thomas S.
  • 5,804
  • 5
  • 37
  • 72
  • You may find http://stackoverflow.com/questions/2018553/swt-no-more-handles useful. – M A Dec 10 '14 at 20:13
  • 1
    Windows has a maximum number GDI objects per process and per session, perhaps another process is consuming a lot of GDI objects. – rafalopez79 Dec 10 '14 at 20:13
  • 1
    The SWT 'no more handles' message is a catch-all message for many different conditions. In this particular case the Windows API `CoCreateInstance` is returning an error – greg-449 Dec 10 '14 at 20:17
  • Greg, do you know under what conditions this API call might return an error? – Thomas S. Dec 11 '14 at 10:53
  • 1
    I have a similar problem, it also dies on TaskBar.createHandle. Were you able to find a solution or what the problem may be? It just started happening, before the system was working correctly. – Josejulio Jan 08 '15 at 18:44
  • @Josejulio, please try SmartGit 6.5.4 - it should catch this particular exception and should continue. – Thomas S. Jan 12 '15 at 13:39
  • @ThomasS. Sorry, SmartGit? – Josejulio Jan 12 '15 at 17:09
  • I assumed you are using SmartGit. In SmartGit 6.5.4 we simply catch this error in continue just as the platform would not support a system taskbar. – Thomas S. Jan 13 '15 at 19:17

1 Answers1

1

I just got the same crash report. To investigate deeper, the following code can be used:

import org.eclipse.swt.internal.win32.OS;
import org.eclipse.swt.widgets.Display;

public class InvestigateSwtProblem {

    static final byte[] CLSID_TaskbarList = new byte[16];
    static final byte[] IID_ITaskbarList3 = new byte[16];

    static {
        OS.IIDFromString("{56FDF344-FD6D-11d0-958A-006097C9A090}\0".toCharArray(), CLSID_TaskbarList); //$NON-NLS-1$
        OS.IIDFromString("{EA1AFB91-9E28-4B86-90E9-9E9F8A5EEFAF}\0".toCharArray(), IID_ITaskbarList3); //$NON-NLS-1$
    }

    public static void main(String[] args) {
        Display display = new Display();

        int /*long*/[] ppv = new int /*long*/ [1];
        int hr = OS.CoCreateInstance(CLSID_TaskbarList, 0, OS.CLSCTX_INPROC_SERVER, IID_ITaskbarList3, ppv);
        System.out.println("Result of CoCreateInstance = " + hr);
    }
}

In my case, the error was -2147024882, which I found in winerror.h to be:

//
// MessageId: E_OUTOFMEMORY
//
// MessageText:
//
// Ran out of memory
//
#define E_OUTOFMEMORY                    _HRESULT_TYPEDEF_(0x8007000EL)

I still don't know the reason or the solution, but at least you have something to tell the sysadmin.

PS. this if for 32 bit SWT. I haven't tested on 64 bit SWT, but I guess you should replace int with long where int /*long*/ appears in the code.

andi
  • 912
  • 1
  • 10
  • 25