Skip to content

Commit 966ed51

Browse files
Fix crash in PanelSyncHandler and TextFieldHandler (#133)
Co-authored-by: brachy <45517902+brachy84@users.noreply.github.com>
1 parent bb2408a commit 966ed51

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

src/main/java/com/cleanroommc/modularui/value/sync/PanelSyncHandler.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,11 @@ public void closeSubPanels() {
112112
@ApiStatus.Internal
113113
@Override
114114
public void closePanelInternal() {
115-
getSyncManager().getModularSyncManager().close(this.panelName);
116115
this.open = false;
116+
// Sync infrastructure may already be torn down if the screen was disposed
117+
// (e.g. deferred PanelManager.dispose() running after ModularNetwork.closeAll())
118+
if (!isValid()) return;
119+
getSyncManager().getModularSyncManager().close(this.panelName);
117120
if (getSyncManager().isClient()) {
118121
syncToServer(SYNC_CLOSE);
119122
}

src/main/java/com/cleanroommc/modularui/widgets/textfield/TextFieldHandler.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,10 @@ private Point insert(List<String> text, List<String> insertion) {
327327
text.addAll(insertion);
328328
return new Point(text.get(text.size() - 1).length(), text.size() - 1);
329329
}
330-
String lineStart = text.get(this.cursor.y).substring(0, this.cursor.x);
331-
String lineEnd = text.get(this.cursor.y).substring(this.cursor.x);
330+
String line = text.get(this.cursor.y);
331+
int cursorX = Math.min(this.cursor.x, line.length());
332+
String lineStart = line.substring(0, cursorX);
333+
String lineEnd = line.substring(cursorX);
332334
if (insertion.size() == 1 && text.size() == 1 && !test(lineStart + insertion.get(0) + lineEnd)) {
333335
return null;
334336
}
@@ -338,7 +340,7 @@ private Point insert(List<String> text, List<String> insertion) {
338340
return null;
339341
}
340342
text.set(this.cursor.y, text.get(this.cursor.y) + lineEnd);
341-
return new Point(this.cursor.x + insertion.get(0).length(), this.cursor.y);
343+
return new Point(cursorX + insertion.get(0).length(), this.cursor.y);
342344
} else {
343345
text.add(this.cursor.y + 1, insertion.get(insertion.size() - 1) + lineEnd);
344346
x = insertion.get(insertion.size() - 1).length();

0 commit comments

Comments
 (0)