Killing all threads

I have wrote a program that takes webcam input and it probably uses a separate thread for that. I have no control over that behavior since it is in the libs. The problem is that when I close my jMonkey’s application window, the other thread(s) still persist. And if I launch the application again, without manually stopping it from the SDK, it says that the camera is busy. I assume that if I publish the application, the hidden thread will still live until killed from the Task Manager. Does anyone know, what is the right way for closing such an application in jME? I think that I could use System.exit(0) or something like that but it is not guaranteed that the user will exit the application like that. He also might just close the window and be in the same situation as I have described above.

Application has a requestclose, taht is called when exiting via windowsclose or similar. Either call the shutdown hook for your camera library there, or use System.close in there , after the jme shutdown succeded.

Ok, I have just tried adding a shutdown hook with System.exit(0) and tried overloading the requestClose() method, putting the same instruction there. Both do not work… any other ideas? )

on simpleApplication.

[java]

@Override

public void destroy()

{

super.destroy();

//blablabla your code here

}

[/java]

Ok now I added to both overloaded requestClose() and destoy(). Inside them I have added an instruction to terminate the camera capture (a method from the lib). So now it quits ok, without leaving any active threads, but actually it crashes with the following exception:





[java]Jan 31, 2012 4:15:13 PM com.jme3.renderer.lwjgl.LwjglRenderer cleanup

INFO: Deleting objects and invalidating state

Exception in thread "AWT-EventQueue-0" quicktime.QTNullPointerException: QuickTime MUST be initialized:quicktime.util.RawEncodedImage

at quicktime.QTObject._ID(QTObject.java:77)

at quicktime.util.QTPointerRef.copyToArray(QTPointerRef.java:176)

at jp.nyatla.nyartoolkit.qt.utils.QtCameraCapture.actionPerformed(QtCameraCapture.java:213)

at javax.swing.Timer.fireActionPerformed(Timer.java:291)

at javax.swing.Timer$DoPostEvent.run(Timer.java:221)

at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)

at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:646)

at java.awt.EventQueue.access$000(EventQueue.java:84)

at java.awt.EventQueue$1.run(EventQueue.java:607)

at java.awt.EventQueue$1.run(EventQueue.java:605)

at java.security.AccessController.doPrivileged(Native Method)

at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:616)

at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)

at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

Jan 31, 2012 4:15:15 PM com.jme3.input.lwjgl.LwjglMouseInput destroy

INFO: Mouse destroyed.

Jan 31, 2012 4:15:15 PM com.jme3.input.lwjgl.LwjglKeyInput destroy

INFO: Keyboard destroyed.

Jan 31, 2012 4:15:15 PM com.jme3.system.lwjgl.LwjglAbstractDisplay deinitInThread

INFO: Display destroyed.

BUILD SUCCESSFUL (total time: 9 seconds)[/java]



And sometimes it also causes the jvm to appcrash with OpenAL being the source.

This is not a jme error, it comes from your camera application.

I thought so because it originates in these libs…



Thanks very much for the help! At least now it fully exits on exit :smiley:

Just guessing from the camera lib’s error but you should probably make sure you aren’t accidentally terminating it twice.

@pspeed - checked all I can… I have verified that I only call it once… also sometimes that happens:



Problem signature:

Problem Event Name: APPCRASH

Application Name: java.exe

Application Version: 6.0.300.12

Application Timestamp: 4ebba126

Fault Module Name: OpenAL32.dll_unloaded

Fault Module Version: 0.0.0.0

Fault Module Timestamp: 4ea646d0

Exception Code: c0000005

Exception Offset: 109e914a

OS Version: 6.1.7601.2.1.0.256.1

Locale ID: 1033

Additional Information 1: 0a9e

Additional Information 2: 0a9e372d3b4ad19135b953a78882e789

Additional Information 3: 0a9e

Additional Information 4: 0a9e372d3b4ad19135b953a78882e789



But I doubt that anybody knows what to do with that… Anyway, the app now exists without leaving running threads… this is satisfactory.

That’s an OpenAL bug that comes from LWJGL. It’s annoying me, too. The devs don’t recognize it, because many of them use lifestyle artifacts or Linux instead of M$ Windoze. :smiley:

@noncom said:
@pspeed - checked all I can.. I have verified that I only call it once... also sometimes that happens:

Problem signature:
Problem Event Name: APPCRASH
Application Name: java.exe
Application Version: 6.0.300.12
Application Timestamp: 4ebba126
Fault Module Name: OpenAL32.dll_unloaded
Fault Module Version: 0.0.0.0
Fault Module Timestamp: 4ea646d0
Exception Code: c0000005
Exception Offset: 109e914a
OS Version: 6.1.7601.2.1.0.256.1
Locale ID: 1033
Additional Information 1: 0a9e
Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
Additional Information 3: 0a9e
Additional Information 4: 0a9e372d3b4ad19135b953a78882e789

But I doubt that anybody knows what to do with that.. Anyway, the app now exists without leaving running threads.. this is satisfactory.


As someone else mentioned, that one looks different.

But I was reading the exception that you get again and it acts like the video stuff is not shut down properly (maybe shutdown from the wrong thread?) because there is still a Timer trying to do stuff but the libraries have been closed.