From ee2c18211a5128f5cde5312a7bbb5c0e80674903 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 27 Mar 2015 15:10:54 +0100 Subject: Bug 1116: Add ShutdownHook for all factories and devices to StereoDeviceFactory using NativeWindowFactory --- .../classes/jogamp/opengl/oculusvr/OVRStereoDevice.java | 13 ++++++++++--- .../jogamp/opengl/oculusvr/OVRStereoDeviceFactory.java | 17 +++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) (limited to 'src/oculusvr/classes/jogamp') diff --git a/src/oculusvr/classes/jogamp/opengl/oculusvr/OVRStereoDevice.java b/src/oculusvr/classes/jogamp/opengl/oculusvr/OVRStereoDevice.java index fda554fdd..3abea5839 100644 --- a/src/oculusvr/classes/jogamp/opengl/oculusvr/OVRStereoDevice.java +++ b/src/oculusvr/classes/jogamp/opengl/oculusvr/OVRStereoDevice.java @@ -128,9 +128,16 @@ public class OVRStereoDevice implements StereoDevice { @Override public final void dispose() { - OVR.ovrHmd_Destroy(hmdDesc); - hmdDesc = null; - handle = null; + if( isValid() ) { + OVR.ovrHmd_Destroy(hmdDesc); + hmdDesc = null; + handle = null; + } + } + + @Override + public boolean isValid() { + return null != hmdDesc && null != handle; } @Override diff --git a/src/oculusvr/classes/jogamp/opengl/oculusvr/OVRStereoDeviceFactory.java b/src/oculusvr/classes/jogamp/opengl/oculusvr/OVRStereoDeviceFactory.java index eecc15c3f..772891115 100644 --- a/src/oculusvr/classes/jogamp/opengl/oculusvr/OVRStereoDeviceFactory.java +++ b/src/oculusvr/classes/jogamp/opengl/oculusvr/OVRStereoDeviceFactory.java @@ -63,12 +63,14 @@ public class OVRStereoDeviceFactory extends StereoDeviceFactory { return false; } + private boolean isValid = true; + private void dumpCaps(final ovrHmdDesc hmdDesc, final int deviceIndex) { System.err.println(OVRVersion.getAvailableCapabilitiesInfo(hmdDesc, deviceIndex, null).toString()); } @Override - public final StereoDevice createDevice(final int deviceIndex, final StereoDeviceConfig config, final boolean verbose) { + protected final StereoDevice createDeviceImpl(final int deviceIndex, final StereoDeviceConfig config, final boolean verbose) { final ovrHmdDesc hmdDesc = OVR.ovrHmd_Create(deviceIndex); if( null == hmdDesc ) { if( verbose ) { @@ -86,12 +88,19 @@ public class OVRStereoDeviceFactory extends StereoDeviceFactory { if( verbose ) { dumpCaps(hmdDesc, deviceIndex); } - final OVRStereoDevice ctx = new OVRStereoDevice(this, hmdDesc, deviceIndex); - return ctx; + return new OVRStereoDevice(this, hmdDesc, deviceIndex); + } + + @Override + public boolean isValid() { + return isValid; } @Override public final void shutdown() { - OVR.ovr_Shutdown(); + if( isValid ) { + OVR.ovr_Shutdown(); + isValid = false; + } } } -- cgit v1.2.3