Skip to content

Commit

Permalink
Merge pull request #4732 from kwvanderlinde/bugfix/4730-handle-non-po…
Browse files Browse the repository at this point in the history
…sitive-frame-rate

Enforce valid frame rate cap values
  • Loading branch information
cwisniew authored Mar 30, 2024
2 parents 43de7ba + cf79fc1 commit d6ffeea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/main/java/net/rptools/maptool/client/AppPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -1286,11 +1286,21 @@ public static void setMovementMetric(WalkerMetric metric) {
}

public static void setFrameRateCap(int cap) {
if (cap <= 0) {
// The provided value is invalid. Change to default instead.
cap = DEFAULT_FRAME_RATE_CAP;
}
prefs.putInt(KEY_FRAME_RATE_CAP, cap);
}

public static int getFrameRateCap() {
return prefs.getInt(KEY_FRAME_RATE_CAP, DEFAULT_FRAME_RATE_CAP);
int result = prefs.getInt(KEY_FRAME_RATE_CAP, DEFAULT_FRAME_RATE_CAP);
if (result <= 0) {
// An invalid value is stored. Fix that.
result = DEFAULT_FRAME_RATE_CAP;
setFrameRateCap(result);
}
return result;
}

public static void setUpnpDiscoveryTimeout(int timeout) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -939,14 +939,20 @@ public void focusLost(FocusEvent e) {
protected void storeNumericValue(Integer value) {
AppPreferences.setFrameRateCap(value);

// AppPreferences may have rejected the value, so read it back.
final var cap = AppPreferences.getFrameRateCap();
for (final var renderer : MapTool.getFrame().getZoneRenderers()) {
renderer.setFrameRateCap(value);
renderer.setFrameRateCap(cap);
}
}

@Override
protected Integer convertString(String value) throws ParseException {
return StringUtil.parseInteger(value);
final var result = StringUtil.parseInteger(value);
if (result <= 0) {
throw new ParseException("Frame rate cap must be positive", 0);
}
return result;
}
});

Expand Down

0 comments on commit d6ffeea

Please sign in to comment.