Skip to content

Commit c4abe1c

Browse files
committed
Merge 1.18 into 1.19.2
2 parents 48fdb94 + 6f710f1 commit c4abe1c

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

fabric/src/main/java/org/embeddedt/modernfix/fabric/mixin/perf/dynamic_resources/ModelBakeryMixin.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery {
101101
private Cache<ResourceLocation, UnbakedModel> loadedModels;
102102

103103
private HashMap<ResourceLocation, UnbakedModel> smallLoadingCache = new HashMap<>();
104+
private Map<ResourceLocation, UnbakedModel> vanillaUnbakedStorage;
104105

105106
private boolean inTextureGatheringPass;
106107

@@ -124,11 +125,11 @@ private void replaceTopLevelBakedModels(ProfilerFiller filler, String s) {
124125
.softValues()
125126
.build();
126127
// temporarily replace this map to capture models into the small loading cache
127-
Map<ResourceLocation, UnbakedModel> oldMap = this.unbakedCache;
128+
vanillaUnbakedStorage = this.unbakedCache;
128129
this.unbakedCache = new ForwardingMap<ResourceLocation, UnbakedModel>() {
129130
@Override
130131
protected Map<ResourceLocation, UnbakedModel> delegate() {
131-
return oldMap;
132+
return vanillaUnbakedStorage;
132133
}
133134

134135
@Override
@@ -316,6 +317,31 @@ public UnbakedModel put(ResourceLocation key, UnbakedModel value) {
316317
ModernFix.LOGGER.info("Early model bake took {}", watch);
317318
ModernFix.LOGGER.info("{} unbaked models, {} baked models loaded permanently", this.unbakedCache.size(), this.bakedCache.size());
318319
this.unbakedCache = new LayeredForwardingMap<>(new Map[] { this.unbakedCache, mutableBackingMap });
320+
// prevent writes from hitting the vanilla map, which prevents GC of models
321+
Map<ResourceLocation, UnbakedModel> oldVanillaStorage = vanillaUnbakedStorage;
322+
vanillaUnbakedStorage = new ForwardingMap<ResourceLocation, UnbakedModel>() {
323+
@Override
324+
protected Map<ResourceLocation, UnbakedModel> delegate() {
325+
return oldVanillaStorage;
326+
}
327+
328+
@Override
329+
public UnbakedModel put(ResourceLocation key, UnbakedModel value) {
330+
UnbakedModel old = get(key);
331+
if(old != null)
332+
remove(key);
333+
return old;
334+
}
335+
336+
@Override
337+
public void putAll(Map<? extends ResourceLocation, ? extends UnbakedModel> map) {
338+
339+
}
340+
341+
@Override
342+
public void clear() {
343+
}
344+
};
319345
this.bakedTopLevelModels = new DynamicBakedModelProvider((ModelBakery)(Object)this, bakedCache);
320346
if(this.bakedMissingModel != null)
321347
((DynamicBakedModelProvider)this.bakedTopLevelModels).setMissingModel(this.bakedMissingModel);

0 commit comments

Comments
 (0)