Fix iterators in WindowsManager and GLFWInput which didn't allow to remove items from loops
This commit is contained in:
@@ -63,7 +63,9 @@ public final class WindowManager extends BaseWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void closeAll() {
|
public void closeAll() {
|
||||||
for (var ignored : windows) {
|
|
||||||
|
// Use iterator to support removal from loop inside
|
||||||
|
for (var iterator = windows.iterator(); iterator.hasNext(); ) {
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,17 +23,19 @@ public class GLFWInput implements Input {
|
|||||||
this.windowHandle = screen.getID();
|
this.windowHandle = screen.getID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("ForLoopReplaceableByForEach")
|
||||||
public GLFWInput init() {
|
public GLFWInput init() {
|
||||||
log.info("Registering key callback");
|
log.info("Registering key callback");
|
||||||
glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> {
|
glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> {
|
||||||
var event = GLFWKeyEvent.of(key, action);
|
var event = GLFWKeyEvent.of(key, action);
|
||||||
|
|
||||||
for (var handler : keyEventHandlers) {
|
// Use iterator to support removal from loop inside
|
||||||
|
for (var iterator = keyEventHandlers.iterator(); iterator.hasNext(); ) {
|
||||||
if (event.isConsumed()) {
|
if (event.isConsumed()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
handler.handleKeyEvent(event);
|
iterator.next().handleKeyEvent(event);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user