Skip to content

Commit 1372737

Browse files
committed
Camera: add runtime checks for the viewport bounds
1 parent 75f0b73 commit 1372737

1 file changed

Lines changed: 26 additions & 13 deletions

File tree

jme3-core/src/main/java/com/jme3/renderer/Camera.java

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009-2021 jMonkeyEngine
2+
* Copyright (c) 2009-2025 jMonkeyEngine
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -179,22 +179,22 @@ public enum FrustumIntersect {
179179
//view port coordinates
180180
/**
181181
* Percent value on display where horizontal viewing starts for this camera.
182-
* Default is 0.
182+
* Default is 0. Must be less than {@code viewPortRight}.
183183
*/
184184
protected float viewPortLeft;
185185
/**
186186
* Percent value on display where horizontal viewing ends for this camera.
187-
* Default is 1.
187+
* Default is 1. Must be greater than {@code viewPortLeft}.
188188
*/
189189
protected float viewPortRight;
190190
/**
191191
* Percent value on display where vertical viewing ends for this camera.
192-
* Default is 1.
192+
* Default is 1. Must be greater than {@code viewPortBottom}.
193193
*/
194194
protected float viewPortTop;
195195
/**
196196
* Percent value on display where vertical viewing begins for this camera.
197-
* Default is 0.
197+
* Default is 0. Must be less than {@code viewPortTop}.
198198
*/
199199
protected float viewPortBottom;
200200
/**
@@ -1017,7 +1017,8 @@ public float getViewPortLeft() {
10171017
/**
10181018
* Sets the left boundary of the viewport.
10191019
*
1020-
* @param left the left boundary of the viewport
1020+
* @param left the left boundary of the viewport (<viewPortRight,
1021+
* default: 0)
10211022
*/
10221023
public void setViewPortLeft(float left) {
10231024
viewPortLeft = left;
@@ -1036,7 +1037,8 @@ public float getViewPortRight() {
10361037
/**
10371038
* Sets the right boundary of the viewport.
10381039
*
1039-
* @param right the right boundary of the viewport
1040+
* @param right the right boundary of the viewport (>viewPortLeft,
1041+
* default: 1)
10401042
*/
10411043
public void setViewPortRight(float right) {
10421044
viewPortRight = right;
@@ -1055,7 +1057,8 @@ public float getViewPortTop() {
10551057
/**
10561058
* Sets the top boundary of the viewport.
10571059
*
1058-
* @param top the top boundary of the viewport
1060+
* @param top the top boundary of the viewport (>viewPortBottom,
1061+
* default: 1)
10591062
*/
10601063
public void setViewPortTop(float top) {
10611064
viewPortTop = top;
@@ -1074,7 +1077,8 @@ public float getViewPortBottom() {
10741077
/**
10751078
* Sets the bottom boundary of the viewport.
10761079
*
1077-
* @param bottom the bottom boundary of the viewport
1080+
* @param bottom the bottom boundary of the viewport (<viewPortTop,
1081+
* default: 0)
10781082
*/
10791083
public void setViewPortBottom(float bottom) {
10801084
viewPortBottom = bottom;
@@ -1084,10 +1088,10 @@ public void setViewPortBottom(float bottom) {
10841088
/**
10851089
* Sets the boundaries of the viewport.
10861090
*
1087-
* @param left the left boundary of the viewport (default: 0)
1088-
* @param right the right boundary of the viewport (default: 1)
1089-
* @param bottom the bottom boundary of the viewport (default: 0)
1090-
* @param top the top boundary of the viewport (default: 1)
1091+
* @param left the left boundary of the viewport (<right, default: 0)
1092+
* @param right the right boundary of the viewport (>left, default: 1)
1093+
* @param bottom the bottom boundary of the viewport (<top, default: 0)
1094+
* @param top the top boundary of the viewport (>bottom, default: 1)
10911095
*/
10921096
public void setViewPort(float left, float right, float bottom, float top) {
10931097
this.viewPortLeft = left;
@@ -1283,6 +1287,15 @@ public void clearViewportChanged() {
12831287
* Called when the viewport has been changed.
12841288
*/
12851289
public void onViewPortChange() {
1290+
if (!(viewPortBottom < viewPortTop)) {
1291+
throw new IllegalArgumentException(
1292+
"Viewport must have bottom < top");
1293+
}
1294+
if (!(viewPortLeft < viewPortRight)) {
1295+
throw new IllegalArgumentException(
1296+
"Viewport must have left < right");
1297+
}
1298+
12861299
viewportChanged = true;
12871300
setGuiBounding();
12881301
}

0 commit comments

Comments
 (0)