Fix another thread data race issue introduced in #164.

This commit is contained in:
OvermindDL1 authored and Jason Mitchell committed 2024-06-04 21:53:01 -07:00
1 parent af923d1977
commit 84d9dcaf00
1 file changed
+6 -5
@@ -120,11 +120,12 @@ public class LiquidConduitRenderer extends DefaultConduitRenderer implements IRe
public static List<CachableRenderStatement> computeFluidOutlineToCache(CollidableComponent component, Fluid fluid,
double scaleFactor, float outlineWidth) {
Map<Fluid, List<CachableRenderStatement>> cache0 = cache.get(component);
if (cache0 == null) {
cache0 = new ConcurrentHashMap<>();
cache.put(component, cache0);
}
// Only init once per component across all threads so the cache stays accurate.
Map<Fluid, List<CachableRenderStatement>> cache0 = cache
.computeIfAbsent(component, _k -> new ConcurrentHashMap<>());
// The rest of this function 'should' be in a `computeIfAbsent` as well for:
// `cache0.computeIfAbsent(fluid, _k -> ...)` but that won't cause a bug in this case,
// just a bit more garbage.
List<CachableRenderStatement> data = cache0.get(fluid);
if (data != null) {
return data;