Skip to content

Commit 02fc7aa

Browse files
committed
Fix exception in preprocessor
Trying to run sketch with setup() without a body would crash the preprocessor. Now it gives correct error message.
1 parent 6b1578d commit 02fc7aa

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

java/src/processing/mode/java/preproc/PdePreprocessor.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,14 @@ make sure that it uses numbers (or displayWidth/Height), copy into settings
299299
MatchResult setupMatch = findInCurrentScope(VOID_SETUP_REGEX, uncommented);
300300
if (setupMatch != null) {
301301
int start = uncommented.indexOf("{", setupMatch.end());
302-
303-
// Find a closing brace
304-
MatchResult match = findInCurrentScope(CLOSING_BRACE, uncommented, start);
305-
if (match != null) {
306-
searchArea = uncommented.substring(start + 1, match.end() - 1);
307-
} else {
308-
throw new SketchException("Found a { that's missing a matching }", false);
302+
if (start >= 0) {
303+
// Find a closing brace
304+
MatchResult match = findInCurrentScope(CLOSING_BRACE, uncommented, start);
305+
if (match != null) {
306+
searchArea = uncommented.substring(start + 1, match.end() - 1);
307+
} else {
308+
throw new SketchException("Found a { that's missing a matching }", false);
309+
}
309310
}
310311
}
311312
break;

0 commit comments

Comments
 (0)