Skip to content

Commit

Permalink
Fix some crashes from entering invalid values
Browse files Browse the repository at this point in the history
  • Loading branch information
UltimateBoomer committed Feb 15, 2021
1 parent ad3521d commit ad6a517
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public void setManualEntry(boolean manualEntry, boolean cancel) {
if (!cancel) {
String text = entryTextField.getText();
if (NumberUtils.isParsable(text)) {
double value = Double.parseDouble(text);
double value = Math.abs(Double.parseDouble(text));
mod.setScaleFactor(value);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ public void tick() {
protected void applySettingsAndCleanup() {
if (NumberUtils.isParsable(widthTextField.getText())
&& NumberUtils.isParsable(heightTextField.getText())) {
int newWidth = (int) Double.parseDouble(widthTextField.getText());
int newHeight = (int) Double.parseDouble(heightTextField.getText());
int newWidth = (int) Math.abs(Double.parseDouble(widthTextField.getText()));
int newHeight = (int) Math.abs(Double.parseDouble(heightTextField.getText()));

if (newWidth != mod.getScreenshotWidth() || newHeight != mod.getScreenshotHeight()) {
mod.setScreenshotWidth(newWidth);
Expand All @@ -162,8 +162,10 @@ protected void applySettingsAndCleanup() {
private void multiply(double mul) {
if (NumberUtils.isParsable(widthTextField.getText())
&& NumberUtils.isParsable(heightTextField.getText())) {
widthTextField.setText(String.valueOf((int) (Double.parseDouble(widthTextField.getText()) * mul)));
heightTextField.setText(String.valueOf((int) (Double.parseDouble(heightTextField.getText()) * mul)));
widthTextField.setText(String.valueOf(
(int) Math.abs(Double.parseDouble(widthTextField.getText()) * mul)));
heightTextField.setText(String.valueOf(
(int) Math.abs(Double.parseDouble(heightTextField.getText()) * mul)));
calculateSize();
}
}
Expand All @@ -176,7 +178,10 @@ private void resetSize() {
}

private void calculateSize() {
estimatedSize = (long) (Double.parseDouble(widthTextField.getText())
* Double.parseDouble(heightTextField.getText()) * 8);
if (NumberUtils.isParsable(widthTextField.getText())
&& NumberUtils.isParsable(heightTextField.getText())) {
estimatedSize = (long) (Double.parseDouble(widthTextField.getText())
* Double.parseDouble(heightTextField.getText()) * 8);
}
}
}

0 comments on commit ad6a517

Please sign in to comment.