Compare commits

...

4 Commits

Author SHA1 Message Date
Martin Prokoph
e50128d75d chore: bump version 2025-09-27 21:52:37 +02:00
Martin Prokoph
837ead55fb build: switch to official ObsidianUI version
- Previously, I used my own build to achieve 1.21.6 compatibility
2025-09-27 21:46:26 +02:00
Martin Prokoph
c00d5893e9 Merge pull request #365 from FugLong/fix/macosLaunchCrash
fix: resolve ConcurrentModificationException in InputManager.updateBindings
2025-09-27 21:43:58 +02:00
Elijah Stephenson
af4b40e88a fix: resolve ConcurrentModificationException in InputManager.updateBindings
- Make BINDINGS list thread-safe using Collections.synchronizedList()
- Add synchronized blocks around all BINDINGS access methods
- Prevents crash on macOS clients during launch
- Fixes race condition between main thread and controller input thread
2025-09-26 20:20:51 -05:00
6 changed files with 41 additions and 27 deletions

View File

@@ -54,10 +54,6 @@ allprojects {
repositories {
maven { url 'https://aperlambda.github.io/maven' }
maven {
name "MidnightDust Snapshots"
url "https://maven.midnightdust.eu/snapshots"
}
}
dependencies {
implementation('org.aperlambda:lambdajcommon:1.8.1') {

View File

@@ -29,7 +29,7 @@ dependencies {
// Using the Fabric version of midnightlib here to create a common config and get useful utilities
// Just make sure NOT to use classes from the .fabric classpath
modCompileOnlyApi "maven.modrinth:midnightlib:${rootProject.midnightlib_version}-fabric"
modCompileOnlyApi "org.thinkingstudio.obsidianui:ObsidianUI-fabric:${rootProject.obsidianui_version}"
modCompileOnlyApi "maven.modrinth:obsidianui:${rootProject.obsidianui_version}-fabric"
modCompileOnlyApi ("com.terraformersmc:modmenu:${project.modmenu_version}") {
exclude(group: "net.fabricmc.fabric-api")
}

View File

@@ -41,7 +41,7 @@ import static eu.midnightdust.midnightcontrols.client.MidnightControlsClient.cli
*/
public class InputManager {
public static final InputManager INPUT_MANAGER = new InputManager();
private static final List<ButtonBinding> BINDINGS = new ArrayList<>();
private static final List<ButtonBinding> BINDINGS = Collections.synchronizedList(new ArrayList<>());
private static final List<ButtonCategory> CATEGORIES = new ArrayList<>();
public static final Int2ObjectMap<ButtonState> STATES = new Int2ObjectOpenHashMap<>();
public static final Int2FloatMap BUTTON_VALUES = new Int2FloatOpenHashMap();
@@ -109,7 +109,9 @@ public class InputManager {
* @return true if the binding is registered, else false
*/
public static boolean hasBinding(@NotNull ButtonBinding binding) {
return BINDINGS.contains(binding);
synchronized (BINDINGS) {
return BINDINGS.contains(binding);
}
}
/**
@@ -119,7 +121,9 @@ public class InputManager {
* @return true if the binding is registered, else false
*/
public static boolean hasBinding(@NotNull String name) {
return BINDINGS.parallelStream().map(ButtonBinding::getName).anyMatch(binding -> binding.equalsIgnoreCase(name));
synchronized (BINDINGS) {
return BINDINGS.parallelStream().map(ButtonBinding::getName).anyMatch(binding -> binding.equalsIgnoreCase(name));
}
}
/**
@@ -139,18 +143,22 @@ public class InputManager {
* @return true if the binding is registered, else false
*/
public static ButtonBinding getBinding(@NotNull String name) {
if (BINDINGS.parallelStream().map(ButtonBinding::getName).anyMatch(binding -> binding.equalsIgnoreCase(name)))
BINDINGS.forEach(binding -> {
if (binding.getName().equalsIgnoreCase(name)) InputManager.tempBinding = binding;
});
synchronized (BINDINGS) {
if (BINDINGS.parallelStream().map(ButtonBinding::getName).anyMatch(binding -> binding.equalsIgnoreCase(name)))
BINDINGS.forEach(binding -> {
if (binding.getName().equalsIgnoreCase(name)) InputManager.tempBinding = binding;
});
}
return tempBinding;
}
private static List<ButtonBinding> unboundBindings;
public static List<ButtonBinding> getUnboundBindings() {
unboundBindings = new ArrayList<>();
BINDINGS.forEach(binding -> {
if (binding.isNotBound() && !MidnightControlsConfig.ignoredUnboundKeys.contains(binding.getTranslationKey())) unboundBindings.add(binding);
});
synchronized (BINDINGS) {
BINDINGS.forEach(binding -> {
if (binding.isNotBound() && !MidnightControlsConfig.ignoredUnboundKeys.contains(binding.getTranslationKey())) unboundBindings.add(binding);
});
}
unboundBindings.sort(Comparator.comparing(s -> I18n.translate(s.getTranslationKey())));
return unboundBindings;
}
@@ -162,9 +170,11 @@ public class InputManager {
* @return the registered binding
*/
public static @NotNull ButtonBinding registerBinding(@NotNull ButtonBinding binding) {
if (hasBinding(binding))
throw new IllegalStateException("Cannot register twice a button binding in the registry.");
BINDINGS.add(binding);
synchronized (BINDINGS) {
if (BINDINGS.contains(binding))
throw new IllegalStateException("Cannot register twice a button binding in the registry.");
BINDINGS.add(binding);
}
return binding;
}
@@ -284,7 +294,9 @@ public class InputManager {
* @return true if the button has duplicated bindings, else false
*/
public static boolean hasDuplicatedBindings(int[] button) {
return BINDINGS.parallelStream().filter(binding -> areButtonsEquivalent(binding.getButton(), button)).count() > 1;
synchronized (BINDINGS) {
return BINDINGS.parallelStream().filter(binding -> areButtonsEquivalent(binding.getButton(), button)).count() > 1;
}
}
/**
@@ -294,7 +306,9 @@ public class InputManager {
* @return true if the button has duplicated bindings, else false
*/
public static boolean hasDuplicatedBindings(ButtonBinding binding) {
return BINDINGS.parallelStream().filter(other -> areButtonsEquivalent(other.getButton(), binding.getButton()) && other.filter.equals(binding.filter)).count() > 1;
synchronized (BINDINGS) {
return BINDINGS.parallelStream().filter(other -> areButtonsEquivalent(other.getButton(), binding.getButton()) && other.filter.equals(binding.filter)).count() > 1;
}
}
/**
@@ -347,7 +361,8 @@ public class InputManager {
record ButtonStateValue(ButtonState state, float value) {
}
var states = new Object2ObjectOpenHashMap<ButtonBinding, ButtonStateValue>();
for (var binding : BINDINGS) {
synchronized (BINDINGS) {
for (var binding : BINDINGS) {
var state = binding.isAvailable() ? getBindingState(binding) : ButtonState.NONE;
if (skipButtons.intStream().anyMatch(btn -> containsButton(binding.getButton(), btn))) {
if (binding.isPressed())
@@ -368,6 +383,7 @@ public class InputManager {
float value = getBindingValue(binding, state);
states.put(binding, new ButtonStateValue(state, value));
}
}
states.forEach((binding, state) -> {
@@ -387,7 +403,9 @@ public class InputManager {
}
public static @NotNull Stream<ButtonBinding> streamBindings() {
return BINDINGS.stream();
synchronized (BINDINGS) {
return BINDINGS.stream();
}
}
public static @NotNull Stream<ButtonCategory> streamCategories() {

View File

@@ -24,7 +24,7 @@ dependencies {
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
modApi "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_api_version}"
modImplementation include ("maven.modrinth:midnightlib:${rootProject.midnightlib_version}-fabric")
modImplementation include ("org.thinkingstudio.obsidianui:ObsidianUI-fabric:${rootProject.obsidianui_version}")
modImplementation include ("maven.modrinth:obsidianui:${rootProject.obsidianui_version}-fabric")
include 'org.aperlambda:lambdajcommon:1.8.1'
modCompileOnly "maven.modrinth:emi:${project.emi_version}"

View File

@@ -3,12 +3,12 @@ org.gradle.parallel=true
org.gradle.jvmargs=-Xmx2048M
minecraft_version=1.21.6
supported_versions=
supported_versions=1.21.8
yarn_mappings=1.21.6+build.1
enabled_platforms=fabric,neoforge
archives_base_name=midnightcontrols
mod_version=1.11.1
mod_version=1.11.2
maven_group=eu.midnightdust
release_type=release
modrinth_id = bXX9h73M
@@ -27,7 +27,7 @@ quilt_loader_version=0.19.0-beta.18
quilt_fabric_api_version=7.0.1+0.83.0-1.20
sodium_version=mc1.21-0.6.0-beta.1
obsidianui_version=0.2.13+mc1.21.6
obsidianui_version=0.2.12+mc1.21.6
modmenu_version=10.0.0-beta.1
emotecraft_version=2.5.5+1.21.4-fabric
bendylib_version=2.0.+

View File

@@ -41,7 +41,7 @@ configurations {
dependencies {
neoForge "net.neoforged:neoforge:$rootProject.neoforge_version"
modImplementation include ("maven.modrinth:midnightlib:${rootProject.midnightlib_version}-neoforge")
modImplementation include ("org.thinkingstudio.obsidianui:ObsidianUI-neoforge:${rootProject.obsidianui_version}")
modImplementation include ("maven.modrinth:obsidianui:${rootProject.obsidianui_version}-neoforge")
shadowBundle('org.aperlambda:lambdajcommon:1.8.1') {
exclude group: 'com.google.code.gson'
exclude group: 'com.google.guava'