mirror of
https://github.com/shadowfacts/lwjgl2-arm64.git
synced 2026-04-05 06:25:46 +00:00
Added more error checking in OpenAL. Unload native stubs on AL destroy.
This commit is contained in:
parent
53bd9b660d
commit
0ae705b7b0
6 changed files with 74 additions and 78 deletions
|
|
@ -125,15 +125,7 @@ public abstract class AL {
|
|||
create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an OpenAL instance. The empty create will cause OpenAL to
|
||||
* open the default device, and create a context using default values.
|
||||
*/
|
||||
public static void create() throws LWJGLException {
|
||||
if(created) {
|
||||
return;
|
||||
}
|
||||
|
||||
private static String[] getOALPaths() throws LWJGLException {
|
||||
// need to pass path of possible locations of OAL to native side
|
||||
String libpath = System.getProperty("java.library.path");
|
||||
String seperator = System.getProperty("path.separator");
|
||||
|
|
@ -168,43 +160,58 @@ public abstract class AL {
|
|||
|
||||
//add cwd path
|
||||
oalPaths[oalPaths.length - 1] = "";
|
||||
return oalPaths;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an OpenAL instance. The empty create will cause OpenAL to
|
||||
* open the default device, and create a context using default values.
|
||||
*/
|
||||
public static void create() throws LWJGLException {
|
||||
if (created) {
|
||||
return;
|
||||
}
|
||||
String[] oalPaths = getOALPaths();
|
||||
nCreate(oalPaths);
|
||||
|
||||
AL10.initNativeStubs();
|
||||
ALC.create();
|
||||
|
||||
device = ALC.alcOpenDevice(deviceArguments);
|
||||
if (device == null) {
|
||||
ALC.destroy();
|
||||
throw new LWJGLException("Could not open ALC device");
|
||||
}
|
||||
//check if doing default values or not
|
||||
if (contextFrequency == -1) {
|
||||
context = ALC.alcCreateContext(device.device, null);
|
||||
} else {
|
||||
context = ALC.alcCreateContext(device.device,
|
||||
ALCcontext.createAttributeList(contextFrequency, contextRefresh, contextSynchronized));
|
||||
}
|
||||
|
||||
ALC.alcMakeContextCurrent(context.context);
|
||||
|
||||
created = true;
|
||||
|
||||
try {
|
||||
AL10.initNativeStubs();
|
||||
ALC.initNativeStubs();
|
||||
|
||||
device = ALC.alcOpenDevice(deviceArguments);
|
||||
if (device == null)
|
||||
throw new LWJGLException("Could not open ALC device");
|
||||
//check if doing default values or not
|
||||
if (contextFrequency == -1) {
|
||||
context = ALC.alcCreateContext(device.device, null);
|
||||
} else {
|
||||
context = ALC.alcCreateContext(device.device,
|
||||
ALCcontext.createAttributeList(contextFrequency, contextRefresh, contextSynchronized));
|
||||
}
|
||||
if (ALC.alcMakeContextCurrent(context.context) != 0)
|
||||
throw new LWJGLException("Could not make ALC context current");
|
||||
created = true;
|
||||
} catch (LWJGLException e) {
|
||||
destroy();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Exit cleanly by calling destroy.
|
||||
*/
|
||||
public static void destroy() {
|
||||
if(!created) {
|
||||
return;
|
||||
if (context != null) {
|
||||
ALC.alcDestroyContext(context.context);
|
||||
context = null;
|
||||
}
|
||||
|
||||
ALC.alcDestroyContext(context.context);
|
||||
ALC.alcCloseDevice(device.device);
|
||||
ALC.destroy();
|
||||
|
||||
device = null;
|
||||
context = null;
|
||||
if (device != null) {
|
||||
ALC.alcCloseDevice(device.device);
|
||||
device = null;
|
||||
}
|
||||
resetNativeStubs(AL10.class);
|
||||
resetNativeStubs(ALC.class);
|
||||
|
||||
deviceArguments = null;
|
||||
|
||||
|
|
@ -212,8 +219,9 @@ public abstract class AL {
|
|||
contextRefresh = -1;
|
||||
contextSynchronized = ALC.ALC_FALSE;
|
||||
|
||||
if (created)
|
||||
nDestroy();
|
||||
created = false;
|
||||
nDestroy();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -242,5 +250,7 @@ public abstract class AL {
|
|||
Sys.log("Failure locating OpenAL using classloader:" + e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static native void resetNativeStubs(Class clazz);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,9 +67,6 @@ import org.lwjgl.LWJGLException;
|
|||
* @version $Revision$
|
||||
*/
|
||||
public class ALC {
|
||||
/** Has the ALC object been created? */
|
||||
protected static boolean created;
|
||||
|
||||
/** Bad value */
|
||||
public static final int ALC_INVALID = -1;
|
||||
|
||||
|
|
@ -146,41 +143,13 @@ public class ALC {
|
|||
Sys.initialize();
|
||||
}
|
||||
|
||||
/** Creates a new instance of ALC */
|
||||
protected ALC() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to provide any initialization code after creation.
|
||||
*/
|
||||
protected static void init() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the ALC instance
|
||||
*
|
||||
* @throws LWJGLException if a failiure occured in the ALC creation process
|
||||
*/
|
||||
protected static void create() throws LWJGLException {
|
||||
if (created) {
|
||||
return;
|
||||
}
|
||||
initNativeStubs();
|
||||
init();
|
||||
created = true;
|
||||
}
|
||||
|
||||
private static native void initNativeStubs() throws LWJGLException;
|
||||
|
||||
/**
|
||||
* Calls whatever destruction rutines that are needed
|
||||
*/
|
||||
protected static void destroy() {
|
||||
if (!created) {
|
||||
return;
|
||||
}
|
||||
created = false;
|
||||
}
|
||||
static native void initNativeStubs() throws LWJGLException;
|
||||
|
||||
/**
|
||||
* The application can obtain certain strings from ALC.
|
||||
|
|
@ -284,7 +253,7 @@ public class ALC {
|
|||
* @param context address of context to make current
|
||||
* @return true if successfull, false if not
|
||||
*/
|
||||
native static boolean alcMakeContextCurrent(int context);
|
||||
native static int alcMakeContextCurrent(int context);
|
||||
|
||||
/**
|
||||
* The current context is the only context accessible to state changes by AL commands
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue