Skip to content

Commit 2ce18a2

Browse files
committed
Merge pull request processing#4045 from JakubValtar/fix-preproc-crash
Prevent preprocessor from crashing when setup() has no body
2 parents ece6e8d + 02fc7aa commit 2ce18a2

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

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)