Class Checks
- java.lang.Object
-
- org.lwjgl.system.Checks
-
public final class Checks extends java.lang.ObjectA class to check buffer boundaries in general. If there is insufficient space in the buffer when the call is made then a buffer overflow would otherwise occur and cause unexpected behaviour, a crash, or worse, a security risk.Internal class, don't use.
-
-
Field Summary
Fields Modifier and Type Field and Description static booleanCHECKSRuntime checks flag.static booleanDEBUGDebug mode flag.static booleanDEBUG_FUNCTIONSDebug functions flag.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static voidcheckArray(java.lang.Object[] array, int size)static voidcheckBuffer(java.nio.Buffer buf, int size)Helper method to ensure a buffer has enough capacity.static voidcheckBuffer(java.nio.Buffer buf, long size)static voidcheckBuffer(java.lang.CharSequence text, int size)Helper method to ensure a CharSequence has enough characters.static voidcheckBuffer(double[] buf, int size)Helper method to ensure a array has enough capacity.static voidcheckBuffer(float[] buf, int size)Helper method to ensure a array has enough capacity.static voidcheckBuffer(int[] buf, int size)Helper method to ensure a array has enough capacity.static voidcheckBuffer(long[] buf, int size)Helper method to ensure a array has enough capacity.static voidcheckBuffer(PointerBuffer buf, int size)Helper method to ensure aPointerBufferhas enough capacity.static voidcheckBuffer(PointerBuffer buf, long size)static voidcheckBuffer(short[] buf, int size)Helper method to ensure a array has enough capacity.static voidcheckBuffer(StructBuffer<?,?> buf, int size)Helper method to ensure aStructBufferhas enough capacity.static voidcheckBuffer(StructBuffer<?,?> buf, long size)static voidcheckBufferGT(java.nio.Buffer buf, int size)static voidcheckBufferGT(PointerBuffer buf, int size)static voidcheckBufferGT(StructBuffer<?,?> buf, int size)static longcheckFunctionAddress(long pointer)Ensures that the specified function pointer is not-null (0L).static booleancheckFunctions(long... functions)Checks if any of the specified functions pointers isNULL.static float[]checkNT(float[] buf)Ensures that the specified array is null-terminated.static java.nio.FloatBuffercheckNT(java.nio.FloatBuffer buf)Ensures that the specified FloatBuffer is null-terminated.static int[]checkNT(int[] buf)Ensures that the specified array is null-terminated.static int[]checkNT(int[] buf, int terminator)Ensures that the specified array is terminated with the specified terminator.static java.nio.IntBuffercheckNT(java.nio.IntBuffer buf)Ensures that the specified IntBuffer is null-terminated.static java.nio.IntBuffercheckNT(java.nio.IntBuffer buf, int terminator)Ensures that the specified IntBuffer is terminated with the specified terminator.static long[]checkNT(long[] buf)Ensures that the specified array is null-terminated.static java.nio.LongBuffercheckNT(java.nio.LongBuffer buf)Ensures that the specified LongBuffer is null-terminated.static PointerBuffercheckNT(PointerBuffer buf)Ensures that the specified PointerBuffer is null-terminated.static PointerBuffercheckNT(PointerBuffer buf, long terminator)Ensures that the specified PointerBuffer is terminated with the specified terminator.static java.nio.ByteBuffercheckNT1(java.nio.ByteBuffer buf)Ensures that the specified ByteBuffer is null-terminated (last byte equal to 0).static java.nio.ByteBuffercheckNT2(java.nio.ByteBuffer buf)Ensures that the specified ByteBuffer is null-terminated (last 2 bytes equal to 0).static java.nio.ByteBuffercheckNT4(java.nio.ByteBuffer buf)Ensures that the specified ByteBuffer is null-terminated (last 4 bytes equal to 0).static java.nio.ByteBuffercheckNT4(java.nio.ByteBuffer buf, int terminator)Ensures that the specified ByteBuffer is terminated with the specified terminator (last 4 bytes equal toterminator).static java.nio.ByteBuffercheckNT8(java.nio.ByteBuffer buf)Ensures that the specified ByteBuffer is null-terminated (last 8 bytes equal to 0).static java.nio.ByteBuffercheckNTP(java.nio.ByteBuffer buf)Ensures that the specified ByteBuffer is null-terminated (last 4 or 8 bytes equal to 0).static java.nio.ByteBuffercheckNTP(java.nio.ByteBuffer buf, long terminator)Ensures that the specified ByteBuffer is terminated with the specified terminator (last 4 or 8 bytes equal toterminator).static longcheckPointer(long pointer)Ensures that the specified pointer is not-null (0L).
-
-
-
Field Detail
-
CHECKS
public static final boolean CHECKS
Runtime checks flag.When enabled, LWJGL will perform basic checks during its operation, mainly to avoid crashes in native code. Examples of such checks are: context-specific function address validation, buffer capacity checks, null-termination checks, etc. These checks are generally low-overhead and should not have a measurable effect on performance, so its recommended to have them enabled both during development and in production releases.
If maximum performance is required, they can be disabled by setting
Configuration.DISABLE_CHECKSto true.
-
DEBUG
public static final boolean DEBUG
Debug mode flag.When enabled, LWJGL will perform additional checks during its operation. These checks are more expensive than the ones enabled with
Checks.CHECKSand will have a noticeable effect on performance, so they are disabled by default. Examples of such checks are: buffer object binding state check (GL), buffer capacity checks for texture images (GL & CL), etc. LWJGL will also print additional information, mainly during start-up.Can be enabled by setting
Configuration.DEBUGto true.
-
DEBUG_FUNCTIONS
public static final boolean DEBUG_FUNCTIONS
Debug functions flag.When enabled, capabilities classes will print an error message when they fail to retrieve a function pointer.
Can be enabled by setting
Configuration.DEBUG_FUNCTIONSto true.
-
-
Method Detail
-
checkFunctions
public static boolean checkFunctions(long... functions)
Checks if any of the specified functions pointers isNULL.- Parameters:
functions- the function pointers to check- Returns:
- true if all function pointers are valid, false otherwise.
-
checkFunctionAddress
public static long checkFunctionAddress(long pointer)
Ensures that the specified function pointer is not-null (0L).- Parameters:
pointer- the pointer to check- Throws:
java.lang.IllegalStateException
-
checkPointer
public static long checkPointer(long pointer)
Ensures that the specified pointer is not-null (0L).- Parameters:
pointer- the pointer to check- Throws:
java.lang.NullPointerException
-
checkNT1
public static java.nio.ByteBuffer checkNT1(java.nio.ByteBuffer buf)
Ensures that the specified ByteBuffer is null-terminated (last byte equal to 0).
-
checkNT2
public static java.nio.ByteBuffer checkNT2(java.nio.ByteBuffer buf)
Ensures that the specified ByteBuffer is null-terminated (last 2 bytes equal to 0).
-
checkNT4
public static java.nio.ByteBuffer checkNT4(java.nio.ByteBuffer buf)
Ensures that the specified ByteBuffer is null-terminated (last 4 bytes equal to 0).
-
checkNT4
public static java.nio.ByteBuffer checkNT4(java.nio.ByteBuffer buf, int terminator)Ensures that the specified ByteBuffer is terminated with the specified terminator (last 4 bytes equal toterminator).
-
checkNT8
public static java.nio.ByteBuffer checkNT8(java.nio.ByteBuffer buf)
Ensures that the specified ByteBuffer is null-terminated (last 8 bytes equal to 0).
-
checkNTP
public static java.nio.ByteBuffer checkNTP(java.nio.ByteBuffer buf)
Ensures that the specified ByteBuffer is null-terminated (last 4 or 8 bytes equal to 0).
-
checkNTP
public static java.nio.ByteBuffer checkNTP(java.nio.ByteBuffer buf, long terminator)Ensures that the specified ByteBuffer is terminated with the specified terminator (last 4 or 8 bytes equal toterminator).
-
checkNT
public static java.nio.IntBuffer checkNT(java.nio.IntBuffer buf)
Ensures that the specified IntBuffer is null-terminated.
-
checkNT
public static int[] checkNT(int[] buf)
Ensures that the specified array is null-terminated.
-
checkNT
public static java.nio.IntBuffer checkNT(java.nio.IntBuffer buf, int terminator)Ensures that the specified IntBuffer is terminated with the specified terminator.
-
checkNT
public static int[] checkNT(int[] buf, int terminator)Ensures that the specified array is terminated with the specified terminator.
-
checkNT
public static java.nio.LongBuffer checkNT(java.nio.LongBuffer buf)
Ensures that the specified LongBuffer is null-terminated.
-
checkNT
public static long[] checkNT(long[] buf)
Ensures that the specified array is null-terminated.
-
checkNT
public static java.nio.FloatBuffer checkNT(java.nio.FloatBuffer buf)
Ensures that the specified FloatBuffer is null-terminated.
-
checkNT
public static float[] checkNT(float[] buf)
Ensures that the specified array is null-terminated.
-
checkNT
public static PointerBuffer checkNT(PointerBuffer buf)
Ensures that the specified PointerBuffer is null-terminated.
-
checkNT
public static PointerBuffer checkNT(PointerBuffer buf, long terminator)
Ensures that the specified PointerBuffer is terminated with the specified terminator.
-
checkBuffer
public static void checkBuffer(short[] buf, int size)Helper method to ensure a array has enough capacity.- Parameters:
buf- the array to checksize- the minimum array capacity- Throws:
java.lang.IllegalArgumentException
-
checkBuffer
public static void checkBuffer(int[] buf, int size)Helper method to ensure a array has enough capacity.- Parameters:
buf- the array to checksize- the minimum array capacity- Throws:
java.lang.IllegalArgumentException
-
checkBuffer
public static void checkBuffer(long[] buf, int size)Helper method to ensure a array has enough capacity.- Parameters:
buf- the array to checksize- the minimum array capacity- Throws:
java.lang.IllegalArgumentException
-
checkBuffer
public static void checkBuffer(float[] buf, int size)Helper method to ensure a array has enough capacity.- Parameters:
buf- the array to checksize- the minimum array capacity- Throws:
java.lang.IllegalArgumentException
-
checkBuffer
public static void checkBuffer(double[] buf, int size)Helper method to ensure a array has enough capacity.- Parameters:
buf- the array to checksize- the minimum array capacity- Throws:
java.lang.IllegalArgumentException
-
checkBuffer
public static void checkBuffer(java.lang.CharSequence text, int size)Helper method to ensure a CharSequence has enough characters.- Parameters:
text- the text to checksize- the minimum number of characters
-
checkBuffer
public static void checkBuffer(java.nio.Buffer buf, int size)Helper method to ensure a buffer has enough capacity.- Parameters:
buf- the buffer to checksize- the minimum buffer capacity- Throws:
java.lang.IllegalArgumentException
-
checkBuffer
public static void checkBuffer(java.nio.Buffer buf, long size)- See Also:
Checks.checkBuffer(Buffer, int)
-
checkBuffer
public static void checkBuffer(PointerBuffer buf, int size)
Helper method to ensure aPointerBufferhas enough capacity.- Parameters:
buf- the buffer to checksize- the minimum buffer capacity- Throws:
java.lang.IllegalArgumentException
-
checkBuffer
public static void checkBuffer(PointerBuffer buf, long size)
- See Also:
Checks.checkBuffer(PointerBuffer, int)
-
checkBuffer
public static void checkBuffer(StructBuffer<?,?> buf, int size)
Helper method to ensure aStructBufferhas enough capacity.- Parameters:
buf- the buffer to checksize- the minimum buffer capacity- Throws:
java.lang.IllegalArgumentException
-
checkBuffer
public static void checkBuffer(StructBuffer<?,?> buf, long size)
- See Also:
Checks.checkBuffer(StructBuffer, int)
-
checkArray
public static void checkArray(java.lang.Object[] array, int size)
-
checkBufferGT
public static void checkBufferGT(java.nio.Buffer buf, int size)
-
checkBufferGT
public static void checkBufferGT(PointerBuffer buf, int size)
-
checkBufferGT
public static void checkBufferGT(StructBuffer<?,?> buf, int size)
-
-