Added destroy() method to prevent a crash

This commit is contained in:
Caspian Rychlik-Prince 2003-04-28 21:50:11 +00:00
parent 43ff833d99
commit c4305dc5a0
1 changed files with 83 additions and 65 deletions

View File

@ -42,84 +42,102 @@ import org.lwjgl.Sys;
* @version $Revision$ * @version $Revision$
*/ */
public class AL extends CoreAL { public class AL extends CoreAL {
/** ALC instance. */
protected ALC alc;
/** ALCdevice instance. */ /** ALC instance. */
protected ALCdevice device; protected ALC alc;
/** Current ALCcontext. */ /** ALCdevice instance. */
protected ALCcontext context; protected ALCdevice device;
/**
* String that requests a certain device or device configuration.
* If null is specified, the implementation will provide an
* implementation specific default. */
protected String deviceArguments;
/** Frequency for mixing output buffer, in units of Hz. */
protected int contextFrequency = -1;
/** Refresh intervalls, in units of Hz. */
protected int contextRefresh = -1;
/** Flag, indicating a synchronous context. */
protected int contextSynchronized = ALC.FALSE;
/** /** Current ALCcontext. */
* Creates an OpenAL instance. The empty constructor will cause OpenAL to protected ALCcontext context;
* open the default device, and create a context using default values.
*/ /**
public AL() { * String that requests a certain device or device configuration.
} * If null is specified, the implementation will provide an
* implementation specific default. */
protected String deviceArguments;
/** Frequency for mixing output buffer, in units of Hz. */
protected int contextFrequency = -1;
/** Refresh intervalls, in units of Hz. */
protected int contextRefresh = -1;
/** Flag, indicating a synchronous context. */
protected int contextSynchronized = ALC.FALSE;
/** /**
* Creates an OpenAL instance. Using this constructor will cause OpenAL to * Creates an OpenAL instance. The empty constructor will cause OpenAL to
* open the device using supplied device argument, and create a context using the context values * open the default device, and create a context using default values.
* supplied. */
* public AL() {
* @param deviceArguments Arguments supplied to native device }
* @param contextFrequency Frequency for mixing output buffer, in units of Hz (Common values include 11025, 22050, and 44100).
* @param contextRefresh Refresh intervalls, in units of Hz. /**
* @param contextSynchronized Flag, indicating a synchronous context.* * Creates an OpenAL instance. Using this constructor will cause OpenAL to
* open the device using supplied device argument, and create a context using the context values
* supplied.
*
* @param deviceArguments Arguments supplied to native device
* @param contextFrequency Frequency for mixing output buffer, in units of Hz (Common values include 11025, 22050, and 44100).
* @param contextRefresh Refresh intervalls, in units of Hz.
* @param contextSynchronized Flag, indicating a synchronous context.*
*/ */
public AL(String deviceArguments, int contextFrequency, int contextRefresh, boolean contextSynchronized) { public AL(String deviceArguments, int contextFrequency, int contextRefresh, boolean contextSynchronized) {
this.deviceArguments = deviceArguments; this.deviceArguments = deviceArguments;
this.contextFrequency = contextFrequency; this.contextFrequency = contextFrequency;
this.contextRefresh = contextRefresh; this.contextRefresh = contextRefresh;
this.contextSynchronized = contextSynchronized ? ALC.TRUE : ALC.FALSE; this.contextSynchronized = contextSynchronized ? ALC.TRUE : ALC.FALSE;
} }
/**
/**
* @see org.lwjgl.openal.BaseAL#create() * @see org.lwjgl.openal.BaseAL#create()
*/ */
public void create() throws OpenALException { public void create() throws OpenALException {
super.create(); super.create();
alc = new ALC(this);
alc.create();
device = alc.openDevice(deviceArguments);
//check if doing default values or not alc = new ALC(this);
if (contextFrequency == -1) { alc.create();
context = alc.createContext(device.device, 0);
} else {
context = alc.createContext(device.device,
Sys.getDirectBufferAddress(
ALCcontext.createAttributeList(contextFrequency, contextRefresh, contextSynchronized)));
}
device = alc.openDevice(deviceArguments);
alc.makeContextCurrent(context.context);
//check if doing default values or not
if (contextFrequency == -1) {
context = alc.createContext(device.device, 0);
} else {
context =
alc.createContext(
device.device,
Sys.getDirectBufferAddress(
ALCcontext.createAttributeList(contextFrequency, contextRefresh, contextSynchronized)));
}
alc.makeContextCurrent(context.context);
}
/**
* Exit cleanly by calling destroy.
*/
public void destroy() {
alc.destroyContext(context.context);
alc.closeDevice(device.device);
alc.destroy();
}
/**
* Emergency finalizer!
*/
protected void finalize() throws Throwable {
super.finalize();
destroy();
}
/**
* Retrieves the AL Context class
*/
public final ALC getALC() {
return alc;
} }
/**
* Retrieves the AL Context class
*/
public ALC getALC() {
return alc;
}
} }