Skip to content

Commit

Permalink
Fix another thread data race issue introduced in #164.
Browse files Browse the repository at this point in the history
  • Loading branch information
OvermindDL1 authored and mitchej123 committed Jun 5, 2024
1 parent af923d1 commit 84d9dca
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,12 @@ public static void renderFluidOutline(CollidableComponent component, FluidStack
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;
Expand Down

0 comments on commit 84d9dca

Please sign in to comment.