Fabric API

Fabric API

106M Downloads

ConcurrentModificationException when trying to play sounds (client)

CreeperPookie opened this issue ยท 1 comments

commented

Discussed in https://github.com/orgs/FabricMC/discussions/3148

Originally posted by CreeperPookie June 26, 2023

Description

I'm working on a mod that will play NBS files in-game. I've got playback working, but often the game will crash due to a ConcurrentModificationException thrown in HashMap. Something to note is that it doesn't crash instantly, and sometimes rarely doesn't crash at all.
Here's how I'm trying to do this:
I have a TickList class that gets the note blocks on a given tick; on a new Thread, I'm iterating through all the note blocks on the tick and play their respective sound; after this, I sleep the thread and play the next tick of notes until I reach the end of the song. I've tried using the ClientPlayerEntity#playSound and the MinecraftClient.getInstance().getSoundManager()#play methods, but they both still eventually cause the CME.
I don't think it's caused by playing too many notes at once, because it can work correctly for so long before crashing. Because the error is thrown in HashMap, this might be caused by not catching a CME in SoundSystem. I tested my mod on a local LAN Purpur server, but it also occurs in singleplayer. Does anyone know what could be causing this?
I'll provide my crash log below, and I'll provide any mod or class details that would be helpful.
Thank you!

 java.util.ConcurrentModificationException: null
	at java.util.HashMap$HashIterator.nextNode(HashMap.java:1605) ~[?:?]
	at java.util.HashMap$EntryIterator.next(HashMap.java:1638) ~[?:?]
	at java.util.HashMap$EntryIterator.next(HashMap.java:1636) ~[?:?]
	at net.minecraft.client.sound.SoundSystem.tick(SoundSystem.java:279) ~[minecraft-clientonly-project-root-1.19.4-net.fabricmc.yarn.1_19_4.1.19.4+build.2-v2.jar:?]
	at net.minecraft.client.sound.SoundSystem.tick(SoundSystem.java:241) ~[minecraft-clientonly-project-root-1.19.4-net.fabricmc.yarn.1_19_4.1.19.4+build.2-v2.jar:?]
	at net.minecraft.client.sound.SoundManager.tick(SoundManager.java:272) ~[minecraft-clientonly-project-root-1.19.4-net.fabricmc.yarn.1_19_4.1.19.4+build.2-v2.jar:?]
	at net.minecraft.client.MinecraftClient.tick(MinecraftClient.java:1912) ~[minecraft-clientonly-project-root-1.19.4-net.fabricmc.yarn.1_19_4.1.19.4+build.2-v2.jar:?]
	at net.minecraft.client.MinecraftClient.render(MinecraftClient.java:1180) ~[minecraft-clientonly-project-root-1.19.4-net.fabricmc.yarn.1_19_4.1.19.4+build.2-v2.jar:?]
	at net.minecraft.client.MinecraftClient.run(MinecraftClient.java:801) ~[minecraft-clientonly-project-root-1.19.4-net.fabricmc.yarn.1_19_4.1.19.4+build.2-v2.jar:?]
	at net.minecraft.client.main.Main.main(Main.java:237) ~[minecraft-clientonly-project-root-1.19.4-net.fabricmc.yarn.1_19_4.1.19.4+build.2-v2.jar:?]
	at net.fabricmc.loader.impl.game.minecraft.MinecraftGameProvider.launch(MinecraftGameProvider.java:468) ~[fabric-loader-0.14.21.jar:?]
	at net.fabricmc.loader.impl.launch.knot.Knot.launch(Knot.java:74) ~[fabric-loader-0.14.21.jar:?]
	at net.fabricmc.loader.impl.launch.knot.KnotClient.main(KnotClient.java:23) ~[fabric-loader-0.14.21.jar:?]
	at net.fabricmc.devlaunchinjector.Main.main(Main.java:86) ~[dev-launch-injector-0.2.1+build.8.jar:?]
---- Minecraft Crash Report ----
// There are four lights!

Time: 2023-06-26 00:16:06
Description: Unexpected error

java.util.ConcurrentModificationException
	at java.base/java.util.HashMap$HashIterator.nextNode(HashMap.java:1605)
	at java.base/java.util.HashMap$EntryIterator.next(HashMap.java:1638)
	at java.base/java.util.HashMap$EntryIterator.next(HashMap.java:1636)
	at net.minecraft.client.sound.SoundSystem.tick(SoundSystem.java:279)
	at net.minecraft.client.sound.SoundSystem.tick(SoundSystem.java:241)
	at net.minecraft.client.sound.SoundManager.tick(SoundManager.java:272)
	at net.minecraft.client.MinecraftClient.tick(MinecraftClient.java:1912)
	at net.minecraft.client.MinecraftClient.render(MinecraftClient.java:1180)
	at net.minecraft.client.MinecraftClient.run(MinecraftClient.java:801)
	at net.minecraft.client.main.Main.main(Main.java:237)
	at net.fabricmc.loader.impl.game.minecraft.MinecraftGameProvider.launch(MinecraftGameProvider.java:468)
	at net.fabricmc.loader.impl.launch.knot.Knot.launch(Knot.java:74)
	at net.fabricmc.loader.impl.launch.knot.KnotClient.main(KnotClient.java:23)
	at net.fabricmc.devlaunchinjector.Main.main(Main.java:86)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Render thread
Stacktrace:
	at java.base/java.util.HashMap$HashIterator.nextNode(HashMap.java:1605)
	at java.base/java.util.HashMap$EntryIterator.next(HashMap.java:1638)
	at java.base/java.util.HashMap$EntryIterator.next(HashMap.java:1636)
	at net.minecraft.client.sound.SoundSystem.tick(SoundSystem.java:279)
	at net.minecraft.client.sound.SoundSystem.tick(SoundSystem.java:241)
	at net.minecraft.client.sound.SoundManager.tick(SoundManager.java:272)

-- Affected level --
Details:
	All players: 1 total; [ClientPlayerEntity['Player258'/3452, l='ClientLevel', x=-89.82, y=75.00, z=-80.23]]
	Chunk stats: 841, 441
	Level dimension: minecraft:overworld
	Level spawn location: World: (-80,83,-96), Section: (at 0,3,0 in -5,5,-6; chunk contains blocks -80,-64,-96 to -65,319,-81), Region: (-1,-1; contains chunks -32,-32 to -1,-1, blocks -512,-64,-512 to -1,319,-1)
	Level time: 3771876 game time, 1 day time
	Server brand: Purpur
	Server type: Non-integrated multiplayer server
Stacktrace:
	at net.minecraft.client.world.ClientWorld.addDetailsToCrashReport(ClientWorld.java:455)
	at net.minecraft.client.MinecraftClient.addDetailsToCrashReport(MinecraftClient.java:2406)
	at net.minecraft.client.MinecraftClient.run(MinecraftClient.java:825)
	at net.minecraft.client.main.Main.main(Main.java:237)
	at net.fabricmc.loader.impl.game.minecraft.MinecraftGameProvider.launch(MinecraftGameProvider.java:468)
	at net.fabricmc.loader.impl.launch.knot.Knot.launch(Knot.java:74)
	at net.fabricmc.loader.impl.launch.knot.KnotClient.main(KnotClient.java:23)
	at net.fabricmc.devlaunchinjector.Main.main(Main.java:86)

-- Last reload --
Details:
	Reload number: 1
	Reload reason: initial
	Finished: Yes
	Packs: vanilla, fabric

-- System Details --
Details:
	Minecraft Version: 1.19.4
	Minecraft Version ID: 1.19.4
	Operating System: Windows 11 (amd64) version 10.0
	Java Version: 19.0.1, Oracle Corporation
	Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode, sharing), Oracle Corporation
	Memory: 285851336 bytes (272 MiB) / 677380096 bytes (646 MiB) up to 4261412864 bytes (4064 MiB)
	CPUs: 4
	Processor Vendor: GenuineIntel
	Processor Name: Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
	Identifier: Intel64 Family 6 Model 142 Stepping 9
	Microarchitecture: Amber Lake
	Frequency (GHz): 2.90
	Number of physical packages: 1
	Number of physical CPUs: 2
	Number of logical CPUs: 4
	Graphics card #0 name: Intel(R) HD Graphics 620
	Graphics card #0 vendor: Intel Corporation (0x8086)
	Graphics card #0 VRAM (MB): 1024.00
	Graphics card #0 deviceId: 0x5916
	Graphics card #0 versionInfo: DriverVersion=27.20.100.9664
	Graphics card #1 name: NVIDIA GeForce 940MX
	Graphics card #1 vendor: NVIDIA (0x10de)
	Graphics card #1 VRAM (MB): 2048.00
	Graphics card #1 deviceId: 0x134d
	Graphics card #1 versionInfo: DriverVersion=31.0.15.2849
	Memory slot #0 capacity (MB): 16384.00
	Memory slot #0 clockSpeed (GHz): 2.40
	Memory slot #0 type: DDR4
	Virtual memory max (MB): 25809.63
	Virtual memory used (MB): 23626.16
	Swap memory total (MB): 9559.71
	Swap memory used (MB): 1401.93
	JVM Flags: 0 total; 
	Fabric Mods: 
		fabric-api: Fabric API 0.84.0+1.19.4
		fabric-api-base: Fabric API Base 0.4.27+1e9487d2f4
		fabric-api-lookup-api-v1: Fabric API Lookup API (v1) 1.6.28+504944c8f4
		fabric-biome-api-v1: Fabric Biome API (v1) 13.0.9+10ce000ff4
		fabric-block-api-v1: Fabric Block API (v1) 1.0.8+e022e5d1f4
		fabric-blockrenderlayer-v1: Fabric BlockRenderLayer Registration (v1) 1.1.37+10ce000ff4
		fabric-client-tags-api-v1: Fabric Client Tags 1.0.18+10ce000ff4
		fabric-command-api-v2: Fabric Command API (v2) 2.2.9+10ce000ff4
		fabric-content-registries-v0: Fabric Content Registries (v0) 3.5.12+10ce000ff4
		fabric-convention-tags-v1: Fabric Convention Tags 1.5.2+10ce000ff4
		fabric-crash-report-info-v1: Fabric Crash Report Info (v1) 0.2.17+aeb40ebef4
		fabric-data-generation-api-v1: Fabric Data Generation API (v1) 11.4.3+10ce000ff4
		fabric-dimensions-v1: Fabric Dimensions API (v1) 2.1.48+10ce000ff4
		fabric-entity-events-v1: Fabric Entity Events (v1) 1.5.16+10ce000ff4
		fabric-events-interaction-v0: Fabric Events Interaction (v0) 0.6.0+10ce000ff4
		fabric-game-rule-api-v1: Fabric Game Rule API (v1) 1.0.35+a1ccd7bff4
		fabric-gametest-api-v1: Fabric Game Test API (v1) 1.2.7+10ce000ff4
		fabric-item-api-v1: Fabric Item API (v1) 2.1.20+10ce000ff4
		fabric-item-group-api-v1: Fabric Item Group API (v1) 3.0.8+10ce000ff4
		fabric-key-binding-api-v1: Fabric Key Binding API (v1) 1.0.35+504944c8f4
		fabric-lifecycle-events-v1: Fabric Lifecycle Events (v1) 2.2.18+10ce000ff4
		fabric-loot-api-v2: Fabric Loot API (v2) 1.1.30+10ce000ff4
		fabric-message-api-v1: Fabric Message API (v1) 5.1.4+10ce000ff4
		fabric-mining-level-api-v1: Fabric Mining Level API (v1) 2.1.42+10ce000ff4
		fabric-models-v0: Fabric Models (v0) 0.3.33+10ce000ff4
		fabric-networking-api-v1: Fabric Networking API (v1) 1.3.4+10ce000ff4
		fabric-object-builder-api-v1: Fabric Object Builder API (v1) 7.0.6+10ce000ff4
		fabric-particles-v1: Fabric Particles (v1) 1.0.26+10ce000ff4
		fabric-recipe-api-v1: Fabric Recipe API (v1) 1.0.11+10ce000ff4
		fabric-registry-sync-v0: Fabric Registry Sync (v0) 2.2.3+10ce000ff4
		fabric-renderer-api-v1: Fabric Renderer API (v1) 2.4.0+c6bbc80df4
		fabric-renderer-indigo: Fabric Renderer - Indigo 1.4.0+c6bbc80df4
		fabric-rendering-data-attachment-v1: Fabric Rendering Data Attachment (v1) 0.3.31+10ce000ff4
		fabric-rendering-fluids-v1: Fabric Rendering Fluids (v1) 3.0.24+10ce000ff4
		fabric-rendering-v1: Fabric Rendering (v1) 2.1.4+10ce000ff4
		fabric-resource-conditions-api-v1: Fabric Resource Conditions API (v1) 2.3.3+10ce000ff4
		fabric-resource-loader-v0: Fabric Resource Loader (v0) 0.11.5+5ade3c38f4
		fabric-screen-api-v1: Fabric Screen API (v1) 1.0.48+10ce000ff4
		fabric-screen-handler-api-v1: Fabric Screen Handler API (v1) 1.3.23+10ce000ff4
		fabric-sound-api-v1: Fabric Sound API (v1) 1.0.11+10ce000ff4
		fabric-transfer-api-v1: Fabric Transfer API (v1) 3.2.1+10ce000ff4
		fabric-transitive-access-wideners-v1: Fabric Transitive Access Wideners (v1) 3.2.0+10ce000ff4
		fabricloader: Fabric Loader 0.14.21
		java: Java HotSpot(TM) 64-Bit Server VM 19
		minecraft: Minecraft 1.19.4
		nbsplayer: NBS Player 1.0.0
	Launched Version: Fabric
	Backend library: LWJGL version 3.3.2-snapshot
	Backend API: Intel(R) HD Graphics 620 GL version 3.2.0 - Build 27.20.100.9664, Intel
	Window size: 1920x1080
	GL Caps: Using framebuffer using OpenGL 3.2
	GL debug messages: 
	Using VBOs: Yes
	Is Modded: Definitely; Client brand changed to 'fabric'
	Type: Client (map_client.txt)
	Graphics mode: fancy
	Resource Packs: vanilla, fabric
	Current Language: en_us
	CPU: 4x Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz```</div>
commented

๐Ÿ‘‹ We use the issue tracker exclusively for final bug reports and feature requests. However, this issue appears to be better suited for either a discussion thread, or a message on our discord server. Please post your request on one of these, and the conversation can continue there.