Replaced asserts with proper runtime exceptions

This commit is contained in:
Elias Naur 2004-03-27 11:55:07 +00:00
parent afb8491cfa
commit c093f3ace1
11 changed files with 1058 additions and 1013 deletions

View File

@ -196,8 +196,10 @@ public final class Display {
* @param contrast The contrast, larger than 0.0.
*/
public static void setDisplayConfiguration(float gamma, float brightness, float contrast) throws Exception {
assert brightness >= -1.0f && brightness <= 1.0f;
assert contrast >= 0.0f;
if (brightness < -1.0f || brightness > 1.0f)
throw new IllegalArgumentException("Invalid brightness value");
if (contrast < 0.0f)
throw new IllegalArgumentException("Invalid contrast value");
int rampSize = getGammaRampLength();
if (rampSize == 0) {
throw new Exception("Display configuration not supported");

View File

@ -164,9 +164,8 @@ public class Controller {
* @throws Exception if the controller could not be created for any reason
*/
public static void create() throws Exception {
assert Window.isCreated() : "Window must be created prior to creating controller";
if (!Window.isCreated())
throw new IllegalStateException("Window must be created before you can create Controller");
if (!initialized) {
initialize();
}
@ -203,7 +202,8 @@ public class Controller {
* Polls the controller.
*/
public static void poll() {
assert created : "The controller has not been created.";
if (!created)
throw new IllegalStateException("Controller must be created before you can poll the device");
nPoll();
}
@ -215,7 +215,8 @@ public class Controller {
* @see #buttonCount
*/
public static boolean isButtonDown(int button) {
assert created : "The controller has not been created.";
if (!created)
throw new IllegalStateException("Controller must be created before you can query button state");
return buttons[button];
}
@ -231,7 +232,7 @@ public class Controller {
* it always throws a RuntimeException.
*/
public static void read() {
throw new RuntimeException("Buffering is not implemented for Controllers.");
throw new UnsupportedOperationException("Buffering is not implemented for Controllers.");
}
/**

View File

@ -50,185 +50,190 @@ import org.lwjgl.Sys;
public class Cursor {
/** Lazy initialization */
private static boolean initialized = false;
/** First element to display */
private CursorElement[] cursors = null;
/** Index into list of cursors */
private int index = -1;
/**
* Constructs a new Cursor, with the given parameters. Mouse must have been created before you can create
* Cursor objects. Cursor images are in ARGB format, but only one bit transparancy is guaranteed to be supported.
* So to maximize portability, lwjgl applications should only create cursor images with 0x00 or 0xff as alpha values.
* The constructor will copy the images and delays, so there's no need to keep them around.
*
* @param width cursor image width
* @param height cursor image height
* @param xHotspot the x coordinate of the cursor hotspot
* @param yHotspot the y coordinate of the cursor hotspot
* @param numImages number of cursor images specified. Must be 1 if animations are not supported.
* @param images A buffer containing the images. The origin is at the lower left corner, like OpenGL.
* @param delays An int buffer of animation frame delays, if numImages is greater than 1, else null
* @throws Exception if the cursor could not be created for any reason
*/
public Cursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws Exception {
assert Mouse.isCreated();
assert width*height*numImages <= images.remaining() : "width*height*numImages > images.remaining()";
assert delays == null || numImages <= delays.remaining() : "delays != null && numImages > delays.remaining()";
assert xHotspot < width && xHotspot >= 0 : "xHotspot > width || xHotspot < 0";
assert yHotspot < height && yHotspot >= 0 : "yHotspot > height || yHotspot < 0";
// initialize
if (!initialized) {
initialize();
}
// Hmm
yHotspot = height - 1 - yHotspot;
// create cursor (or cursors if multiple images supplied)
createCursors(width, height, xHotspot, yHotspot, numImages, images, delays);
}
/**
* Initializes the cursor class
*/
private static void initialize() {
System.loadLibrary(Sys.getLibraryName());
initialized = true;
}
/** Lazy initialization */
private static boolean initialized = false;
/** First element to display */
private CursorElement[] cursors = null;
/** Index into list of cursors */
private int index = -1;
/**
* Constructs a new Cursor, with the given parameters. Mouse must have been created before you can create
* Cursor objects. Cursor images are in ARGB format, but only one bit transparancy is guaranteed to be supported.
* So to maximize portability, lwjgl applications should only create cursor images with 0x00 or 0xff as alpha values.
* The constructor will copy the images and delays, so there's no need to keep them around.
*
* @param width cursor image width
* @param height cursor image height
* @param xHotspot the x coordinate of the cursor hotspot
* @param yHotspot the y coordinate of the cursor hotspot
* @param numImages number of cursor images specified. Must be 1 if animations are not supported.
* @param images A buffer containing the images. The origin is at the lower left corner, like OpenGL.
* @param delays An int buffer of animation frame delays, if numImages is greater than 1, else null
* @throws Exception if the cursor could not be created for any reason
*/
public Cursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws Exception {
if (!Mouse.isCreated())
throw new IllegalStateException("Mouse must be created before creating cursor objects");
if (width*height*numImages > images.remaining())
throw new IllegalArgumentException("width*height*numImages > images.remaining()");
if (delays != null && numImages > delays.remaining())
throw new IllegalArgumentException("delays != null && numImages > delays.remaining()");
if (xHotspot >= width || xHotspot < 0)
throw new IllegalArgumentException("xHotspot > width || xHotspot < 0");
if (yHotspot >= height || yHotspot < 0)
throw new IllegalArgumentException("yHotspot > height || yHotspot < 0");
// initialize
if (!initialized) {
initialize();
}
// Hmm
yHotspot = height - 1 - yHotspot;
// create cursor (or cursors if multiple images supplied)
createCursors(width, height, xHotspot, yHotspot, numImages, images, delays);
}
/**
* Initializes the cursor class
*/
private static void initialize() {
System.loadLibrary(Sys.getLibraryName());
initialized = true;
}
/**
* Creates the actual cursor, using a platform specific class
*/
private void createCursors(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws Exception {
// create copy and flip images to match ogl
IntBuffer images_copy = ByteBuffer.allocateDirect(images.remaining()*4).order(ByteOrder.nativeOrder()).asIntBuffer();
flipImages(width, height, numImages, images, images_copy);
// create our cursor elements
cursors = new CursorElement[numImages];
for(int i=0; i<numImages; i++) {
cursors[i] = new CursorElement();
cursors[i].cursorHandle = nCreateCursor(width, height, xHotspot, yHotspot, 1, images_copy, images_copy.position());
cursors[i].delay = (delays != null) ? delays.get(i) : 0;
cursors[i].timeout = System.currentTimeMillis();
// offset to next image
images_copy.position(width*height*(i+1));
}
// set index
index = 0;
}
/**
* Creates the actual cursor, using a platform specific class
*/
private void createCursors(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws Exception {
// create copy and flip images to match ogl
IntBuffer images_copy = ByteBuffer.allocateDirect(images.remaining()*4).order(ByteOrder.nativeOrder()).asIntBuffer();
flipImages(width, height, numImages, images, images_copy);
// create our cursor elements
cursors = new CursorElement[numImages];
for(int i=0; i<numImages; i++) {
cursors[i] = new CursorElement();
cursors[i].cursorHandle = nCreateCursor(width, height, xHotspot, yHotspot, 1, images_copy, images_copy.position());
cursors[i].delay = (delays != null) ? delays.get(i) : 0;
cursors[i].timeout = System.currentTimeMillis();
// offset to next image
images_copy.position(width*height*(i+1));
}
// set index
index = 0;
}
/**
* Flips the images so they're oriented according to opengl
*
* @param width Width of image
* @param height Height of images
* @param numImages How many images to flip
* @param images Source images
* @param images_copy Destination images
*/
private static void flipImages(int width, int height, int numImages, IntBuffer images, IntBuffer images_copy) {
for (int i = 0; i < numImages; i++) {
int start_index = i*width*height;
flipImage(width, height, start_index, images, images_copy);
}
}
/**
* Flips the images so they're oriented according to opengl
*
* @param width Width of image
* @param height Height of images
* @param numImages How many images to flip
* @param images Source images
* @param images_copy Destination images
*/
private static void flipImages(int width, int height, int numImages, IntBuffer images, IntBuffer images_copy) {
for (int i = 0; i < numImages; i++) {
int start_index = i*width*height;
flipImage(width, height, start_index, images, images_copy);
}
}
/**
* @param width Width of image
* @param height Height of images
* @param start_index index into source buffer to copy to
* @param images Source images
* @param images_copy Destination images
*/
private static void flipImage(int width, int height, int start_index, IntBuffer images, IntBuffer images_copy) {
for (int y = 0; y < height>>1; y++) {
int index_y_1 = y*width + start_index;
int index_y_2 = (height - y - 1)*width + start_index;
for (int x = 0; x < width; x++) {
int index1 = index_y_1 + x;
int index2 = index_y_2 + x;
int temp_pixel = images.get(index1 + images.position());
images_copy.put(index1, images.get(index2 + images.position()));
images_copy.put(index2, temp_pixel);
}
}
}
/**
* Gets the native handle associated with the cursor object.
*/
public long getHandle() {
return cursors[index].cursorHandle;
}
/**
* Destroy the native cursor. Cursor must not be current.
*/
public void destroy() {
/**
* @param width Width of image
* @param height Height of images
* @param start_index index into source buffer to copy to
* @param images Source images
* @param images_copy Destination images
*/
private static void flipImage(int width, int height, int start_index, IntBuffer images, IntBuffer images_copy) {
for (int y = 0; y < height>>1; y++) {
int index_y_1 = y*width + start_index;
int index_y_2 = (height - y - 1)*width + start_index;
for (int x = 0; x < width; x++) {
int index1 = index_y_1 + x;
int index2 = index_y_2 + x;
int temp_pixel = images.get(index1 + images.position());
images_copy.put(index1, images.get(index2 + images.position()));
images_copy.put(index2, temp_pixel);
}
}
}
/**
* Gets the native handle associated with the cursor object.
*/
public long getHandle() {
return cursors[index].cursorHandle;
}
/**
* Destroy the native cursor. Cursor must not be current.
*/
public void destroy() {
for(int i=0; i<cursors.length; i++) {
nDestroyCursor(cursors[i].cursorHandle);
}
}
nDestroyCursor(cursors[i].cursorHandle);
}
}
/**
* Sets the timout property to the time it should be changed
*/
protected void setTimeout() {
cursors[index].timeout = System.currentTimeMillis() + cursors[index].delay;
}
/**
* Sets the timout property to the time it should be changed
*/
protected void setTimeout() {
cursors[index].timeout = System.currentTimeMillis() + cursors[index].delay;
}
/**
* Determines whether this cursor has timed out
* @return true if the this cursor has timed out, false if not
*/
protected boolean hasTimedOut() {
return cursors.length > 1 && cursors[index].timeout < System.currentTimeMillis();
}
/**
* Determines whether this cursor has timed out
* @return true if the this cursor has timed out, false if not
*/
protected boolean hasTimedOut() {
return cursors.length > 1 && cursors[index].timeout < System.currentTimeMillis();
}
/**
* Changes to the next cursor
*/
protected void nextCursor() {
index = ++index % cursors.length;
}
/**
* Changes to the next cursor
*/
protected void nextCursor() {
index = ++index % cursors.length;
}
/**
* Resets the index of the cursor animation to the first in the list.
*/
public void resetAnimation() {
index = 0;
}
/**
* Native method to create a native cursor
*/
private static native long nCreateCursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, int images_offset);
/**
* Resets the index of the cursor animation to the first in the list.
*/
public void resetAnimation() {
index = 0;
}
/**
* Native method to create a native cursor
*/
private static native long nCreateCursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, int images_offset);
/**
* Native method to destroy a native cursor
*/
private static native void nDestroyCursor(long cursorHandle);
/**
* A single cursor element, used when animating
*/
protected class CursorElement {
/** Handle to cursor */
long cursorHandle;
/** How long a delay this element should have */
long delay;
/** Absolute time this element times out */
long timeout;
}
/**
* Native method to destroy a native cursor
*/
private static native void nDestroyCursor(long cursorHandle);
/**
* A single cursor element, used when animating
*/
protected class CursorElement {
/** Handle to cursor */
long cursorHandle;
/** How long a delay this element should have */
long delay;
/** Absolute time this element times out */
long timeout;
}
}

View File

@ -285,7 +285,8 @@ public class Keyboard {
* @throws Exception if the keyboard could not be created for any reason
*/
public static void create() throws Exception {
assert Window.isCreated() : "Window must be created prior to creating keyboard";
if (!Window.isCreated())
throw new IllegalStateException("Window must be created before you can create Keyboard");
if (!initialized)
initialize();
if (created)
@ -334,7 +335,8 @@ public class Keyboard {
* @see org.lwjgl.input.Keyboard#read()
*/
public static void poll() {
assert created : "The keyboard has not been created.";
if (!created)
throw new IllegalStateException("Keyboard must be created before you can poll the device");
nPoll(keyDownBuffer);
}
@ -361,8 +363,10 @@ public class Keyboard {
* @see org.lwjgl.input.Keyboard#getEventCharacter()
*/
public static void read() {
assert created : "The keyboard has not been created.";
assert readBuffer != null : "Keyboard buffering has not been enabled.";
if (!created)
throw new IllegalStateException("Keyboard must be created before you can read events");
if (readBuffer == null)
throw new IllegalStateException("Event buffering must be enabled before you can read events");
readBuffer.compact();
int numEvents = nRead(readBuffer, readBuffer.position());
if (translationEnabled)
@ -383,8 +387,10 @@ public class Keyboard {
* and keyboard buffering must be enabled.
*/
public static void enableTranslation() throws Exception {
assert created : "The keyboard has not been created.";
assert readBuffer != null : "Keyboard buffering has not been enabled.";
if (!created)
throw new IllegalStateException("Keyboard must be created before you can read events");
if (readBuffer == null)
throw new IllegalStateException("Event buffering must be enabled before you can read events");
nEnableTranslation();
translationEnabled = true;
}
@ -398,7 +404,8 @@ public class Keyboard {
* Enable keyboard buffering. Must be called after the keyboard is created.
*/
public static void enableBuffer() throws Exception {
assert created : "The keyboard has not been created.";
if (!created)
throw new IllegalStateException("Keyboard must be created before you can enable buffering");
readBuffer = BufferUtils.createByteBuffer(4*BUFFER_SIZE);
readBuffer.limit(0);
nEnableBuffer();
@ -417,7 +424,8 @@ public class Keyboard {
* @return true if the key is down according to the last poll()
*/
public static boolean isKeyDown(int key) {
assert created : "The keyboard has not been created.";
if (!created)
throw new IllegalStateException("Keyboard must be created before you can query key state");
return keyDownBuffer.get(key) != 0;
}
@ -442,7 +450,8 @@ public class Keyboard {
* @return STATE_ON if on, STATE_OFF if off and STATE_UNKNOWN if the state is unknown
*/
public static int isStateKeySet(int key) {
assert created : "The keyboard has not been created.";
if (!created)
throw new IllegalStateException("Keyboard must be created before you can query key state");
return nisStateKeySet(key);
}
private static native int nisStateKeySet(int key);
@ -473,7 +482,8 @@ public class Keyboard {
* @return the number of keyboard events
*/
public static int getNumKeyboardEvents() {
assert created : "The keyboard has not been created.";
if (!created)
throw new IllegalStateException("Keyboard must be created before you can read events");
if (translationEnabled)
return readBuffer.remaining()/4;
else
@ -492,8 +502,10 @@ public class Keyboard {
* @return true if a keyboard event was read, false otherwise
*/
public static boolean next() {
assert created : "The keyboard has not been created.";
assert readBuffer != null : "Keyboard buffering has not been enabled.";
if (!created)
throw new IllegalStateException("Keyboard must be created before you can read events");
if (readBuffer == null)
throw new IllegalStateException("Event buffering must be enabled before you can read events");
if (readBuffer.hasRemaining()) {
eventKey = readBuffer.get() & 0xFF;

View File

@ -167,7 +167,10 @@ public class Mouse {
* @throws Exception if the cursor could not be set for any reason
*/
public static Cursor setNativeCursor(Cursor cursor) throws Exception {
assert created && ((getNativeCursorCaps() | CURSOR_ONE_BIT_TRANSPARENCY) != 0);
if (!created)
throw new IllegalStateException("Create the Mouse before setting the native cursor");
if ((getNativeCursorCaps() & CURSOR_ONE_BIT_TRANSPARENCY) == 0)
throw new IllegalStateException("Mouse doesn't support native cursors");
Cursor oldCursor = currentCursor;
currentCursor = cursor;
if (currentCursor != null) {
@ -239,7 +242,8 @@ public class Mouse {
*/
public static void create() throws Exception {
assert Window.isCreated() : "Window must be created prior to creating mouse";
if (!Window.isCreated())
throw new IllegalStateException("Window must be created prior to creating mouse");
if (!initialized) {
initialize();
@ -327,7 +331,8 @@ public class Mouse {
* @see org.lwjgl.input.Mouse#read()
*/
public static void poll() {
assert created : "The mouse has not been created.";
if (!created)
throw new IllegalStateException("Mouse must be created before you can poll it");
nPoll();
// set absolute position
@ -363,7 +368,8 @@ public class Mouse {
* @return true if the specified button is down
*/
public static boolean isButtonDown(int button) {
assert created : "The mouse has not been created.";
if (!created)
throw new IllegalStateException("Mouse must be created before you can poll the button state");
if (button >= buttonCount || button < 0)
return false;
else
@ -398,7 +404,8 @@ public class Mouse {
* Enable mouse button buffering. Must be called after the mouse is created.
*/
public static void enableBuffer() throws Exception {
assert created : "The mouse has not been created.";
if (!created)
throw new IllegalStateException("Mouse must be created before you can enable buffering");
readBuffer = BufferUtils.createByteBuffer(2*BUFFER_SIZE);
readBuffer.limit(0);
nEnableBuffer();
@ -424,8 +431,10 @@ public class Mouse {
* @see org.lwjgl.input.Mouse#getEventButtonState()
*/
public static void read() {
assert created : "The mouse has not been created.";
assert readBuffer != null : "Mouse buffering has not been enabled.";
if (!created)
throw new IllegalStateException("Mouse must be created before you can read events");
if (readBuffer == null)
throw new IllegalStateException("Event buffering must be enabled before you can read events");
readBuffer.compact();
int numEvents = nRead(readBuffer, readBuffer.position());
readBuffer.position(readBuffer.position() + numEvents*2);
@ -447,8 +456,10 @@ public class Mouse {
* @return true if a mouse event was read, false otherwise
*/
public static boolean next() {
assert created : "The mouse has not been created.";
assert readBuffer != null : "Mouse buffering has not been enabled.";
if (!created)
throw new IllegalStateException("Mouse must be created before you can read events");
if (readBuffer == null)
throw new IllegalStateException("Event buffering must be enabled before you can read events");
if (readBuffer.hasRemaining()) {
eventButton = readBuffer.get() & 0xFF;

File diff suppressed because it is too large Load Diff

View File

@ -89,7 +89,7 @@ public final class ARBVertexBufferObject {
case GL_ARRAY_BUFFER_ARB:
VBOTracker.getVBOArrayStack().setState(buffer);
break;
default: assert false: "Unsupported VBO target " + target;
default: throw new IllegalArgumentException("Unsupported VBO target " + target);
}
nglBindBufferARB(target, buffer);
}

View File

@ -67,7 +67,7 @@ public final class ARBVertexShader {
// ---------------------------
public static void glBindAttribLocationARB(int programObj, int index, ByteBuffer name) {
if ( name.get(name.limit() - 1) != 0 ) {
throw new RuntimeException("<name> must be a null-terminated string.");
throw new IllegalArgumentException("<name> must be a null-terminated string.");
}
nglBindAttribLocationARB(programObj, index, name, name.position());
}
@ -99,7 +99,7 @@ public final class ARBVertexShader {
// ---------------------------
public static int glGetAttribLocationARB(int programObj, ByteBuffer name) {
if ( name.get(name.limit() - 1) != 0 ) {
throw new RuntimeException("<name> must be a null-terminated string.");
throw new IllegalArgumentException("<name> must be a null-terminated string.");
}
return nglGetAttribLocationARB(programObj, name, name.position());
}
@ -107,4 +107,4 @@ public final class ARBVertexShader {
private static native int nglGetAttribLocationARB(int programObj, ByteBuffer name, int nameOffset);
// ---------------------------
}
}

View File

@ -68,7 +68,7 @@ public final class ATIDrawBuffers {
// ---------------------------
public static void glDrawBuffersATI(IntBuffer buffers) {
if (buffers.remaining() == 0) {
throw new RuntimeException("<buffers> must have at least 1 integer available.");
throw new IllegalArgumentException("<buffers> must have at least 1 integer available.");
}
nglDrawBuffersATI(buffers.remaining(), buffers, buffers.position());
}
@ -76,4 +76,4 @@ public final class ATIDrawBuffers {
private static native void nglDrawBuffersATI(int size, IntBuffer buffers, int buffersOffset);
// ---------------------------
}
}

View File

@ -87,7 +87,7 @@ public final class GL15 {
VBOTracker.getVBOArrayStack().setState(buffer);
break;
default:
assert false: "Unsupported VBO target " + target;
throw new IllegalArgumentException("Unsupported VBO target " + target);
}
nglBindBuffer(target, buffer);
}
@ -296,4 +296,4 @@ public final class GL15 {
int paramsOffset);
// ---------------------------
}
}

View File

@ -108,7 +108,8 @@ public final class Window {
* @return the width of the window
*/
public static int getWidth() {
assert isCreated() : "Cannot get width on uncreated window";
if (!isCreated())
throw new IllegalStateException("Cannot get width on uncreated window");
return width;
}
@ -116,7 +117,8 @@ public final class Window {
* @return the height of the window
*/
public static int getHeight() {
assert isCreated() : "Cannot get height on uncreated window";
if (!isCreated())
throw new IllegalStateException("Cannot get height on uncreated window");
return height;
}
@ -124,15 +126,17 @@ public final class Window {
* @return the title of the window
*/
public static String getTitle() {
assert isCreated() : "Cannot get title on uncreated window";
if (!isCreated())
throw new IllegalStateException("Cannot get title on uncreated window");
return title;
}
/**
* @return whether this window is in fullscreen mode
*/
public static boolean isFullscreen() {
assert isCreated() : "Cannot determine state of uncreated window";
if (!isCreated())
throw new IllegalStateException("Cannot determine fullscreen state of uncreated window");
return fullscreen;
}
@ -141,7 +145,8 @@ public final class Window {
* @param newTitle The new window title
*/
public static void setTitle(String newTitle) {
assert isCreated() : "Cannot set title of uncreated window";
if (!isCreated())
throw new IllegalStateException("Cannot set title on uncreated window");
title = newTitle;
nSetTitle(title);
}
@ -156,7 +161,8 @@ public final class Window {
* @return true if the user or operating system has asked the window to close
*/
public static boolean isCloseRequested() {
assert isCreated() : "Cannot determine state of uncreated window";
if (!isCreated())
throw new IllegalStateException("Cannot determine close requested state of uncreated window");
return nIsCloseRequested();
}
@ -166,7 +172,8 @@ public final class Window {
* @return true if the window is minimized or otherwise not visible
*/
public static boolean isMinimized() {
assert isCreated() : "Cannot determine state of uncreated window";
if (!isCreated())
throw new IllegalStateException("Cannot determine minimized state of uncreated window");
return nIsMinimized();
}
@ -176,7 +183,8 @@ public final class Window {
* @return true if window is focused
*/
public static boolean isFocused() {
assert isCreated() : "Cannot determine state of uncreated window";
if (!isCreated())
throw new IllegalStateException("Cannot determine focused state of uncreated window");
return nIsFocused();
}
@ -210,7 +218,8 @@ public final class Window {
* and needs to repaint itself
*/
public static boolean isDirty() {
assert isCreated() : "Cannot determine state of uncreated window";
if (!isCreated())
throw new IllegalStateException("Cannot determine dirty state of uncreated window");
return nIsDirty();
}
@ -222,7 +231,8 @@ public final class Window {
* @throws OpenGLException if an OpenGL error has occured since the last call to GL11.glGetError()
*/
public static void update() {
assert isCreated() : "Cannot paint uncreated window";
if (!isCreated())
throw new IllegalStateException("Cannot determine update uncreated window");
nUpdate();
if ((isDirty() && !isMinimized()) || (isFocused() && !isMinimized())) {
Util.checkGLError();
@ -259,7 +269,8 @@ public final class Window {
* Make the Window the current rendering context for GL calls.
*/
public static synchronized void makeCurrent() {
assert isCreated() : "No window has been created.";
if (!isCreated())
throw new IllegalStateException("No window created to make current");
nMakeCurrent();
GLContext.useContext(context);
}
@ -315,7 +326,7 @@ public final class Window {
*/
public static void create(String title, int bpp, int alpha, int depth, int stencil, int samples) throws Exception {
if (isCreated())
throw new Exception("Only one LWJGL window may be instantiated at any one time.");
throw new IllegalStateException("Only one LWJGL window may be instantiated at any one time.");
Window.fullscreen = true;
Window.x = 0;
Window.y = 0;
@ -371,7 +382,7 @@ public final class Window {
public static void create(String title, int x, int y, int width, int height, int bpp, int alpha, int depth, int stencil, int samples)
throws Exception {
if (isCreated())
throw new Exception("Only one LWJGL window may be instantiated at any one time.");
throw new IllegalStateException("Only one LWJGL window may be instantiated at any one time.");
Window.fullscreen = false;
Window.x = x;
Window.y = y;
@ -518,7 +529,8 @@ public final class Window {
* @return boolean
*/
public static boolean isVSyncEnabled() {
assert isCreated() : "Cannot determine sync of uncreated window";
if (isCreated())
throw new IllegalStateException("Cannot determine vsync state of uncreated window");
return nIsVSyncEnabled();
}
@ -531,11 +543,10 @@ public final class Window {
* @param sync true to synchronize; false to ignore synchronization
*/
public static void setVSyncEnabled(boolean sync) {
assert isCreated() : "Cannot set sync of uncreated window";
if (isCreated())
throw new IllegalStateException("Cannot set vsync state of uncreated window");
nSetVSyncEnabled(sync);
}
private static native void nSetVSyncEnabled(boolean sync);
}