Dynamic Trees

Dynamic Trees

25M Downloads

Incompatibility with ModernFix's dynamic resources optimization

embeddedt opened this issue ยท 1 comments

commented

If ModernFix is installed, and its dynamic resources optimization is manually enabled by a user, Dynamic Trees will crash due to its models not being baked. The reason this occurs is because of how your model bake event handler is implemented:

BranchBlockBakedModel.INSTANCES.forEach(BranchBlockBakedModel::setupModels);
BranchBlockBakedModel.INSTANCES.clear();

This code assumes that every model in the game was loaded at startup, which is true in vanilla, but not when this optimization is enabled. The optimization is designed to work correctly with models using the vanilla system or the Forge custom model loader system, however, it cannot work with an event handler designed like yours. Since ModernFix only constructs model instances and bakes models when they are actually needed in gameplay, the INSTANCES global list is never populated, causing none of the models to actually get initialized. This later leads to a NullPointerException when the model needs to return quads.

This was reported to me and reproduced on 1.19.2, however, it may also affect 1.16.5/1.18.2 if they use the same model code. I should note that dynamic resources is not on by default, for compatibility reasons, but I do recommend it to players looking to reduce loading times further and significantly improve memory usage.

For reference, I recently fixed a similar issue in Bumblezone by modifying the code to do the model initialization inside the constructor instead of deferring it to the BakingCompleted handler: TelepathicGrunt/Bumblezone@ce1be46. This matches how vanilla and most other models are designed, and fixes the issue.

commented

This issue has gone stale due to inactivity. Please comment again if it is still an issue.