From ad27133253c459c9f62b68c15f76f6172daf1aa5 Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Tue, 16 Jan 2024 16:59:15 -0800 Subject: [PATCH] Feeling empty - Log a warning and don't allocate any resources when an instancer is created with an empty model. - Log stacktrace starting from the call to InstancerProvider#instancer. - Revert switch to embeddium dep and comment why the rubidium dep is there. --- .../backend/engine/InstancerStorage.java | 20 +++++++++++++++++++ .../engine/indirect/IndirectDrawManager.java | 6 ++++++ .../instancing/InstancedDrawManager.java | 6 ++++++ src/main/resources/META-INF/mods.toml | 6 ++++-- 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/InstancerStorage.java b/src/main/java/com/jozufozu/flywheel/backend/engine/InstancerStorage.java index 99c2f1346..de69900fa 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/InstancerStorage.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/InstancerStorage.java @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.api.event.RenderStage; import com.jozufozu.flywheel.api.instance.Instance; import com.jozufozu.flywheel.api.instance.InstanceType; @@ -51,6 +52,8 @@ public abstract class InstancerStorage> { return (Instancer) instancer; } + maybeWarnEmptyModel(model); + // Create a new instancer and add it to the uninitialized list. instancer = create(type); instancers.put(key, instancer); @@ -59,6 +62,23 @@ public abstract class InstancerStorage> { } } + private static void maybeWarnEmptyModel(Model model) { + if (!model.meshes() + .isEmpty()) { + // All is good. + return; + } + + StringBuilder builder = new StringBuilder(); + builder.append("Creating an instancer for a model with no meshes! Stack trace:"); + StackWalker.getInstance() + .walk(s -> s.skip(3)) // skip 3 to get back to the caller of InstancerProvider#instancer + .forEach(f -> builder.append("\n\t") + .append(f.toString())); + + Flywheel.LOGGER.warn(builder.toString()); + } + public void delete() { instancers.clear(); uninitializedInstancers.clear(); diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/IndirectDrawManager.java b/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/IndirectDrawManager.java index ea64cc5d4..781ddd06e 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/IndirectDrawManager.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/IndirectDrawManager.java @@ -46,6 +46,12 @@ public class IndirectDrawManager extends InstancerStorage> @SuppressWarnings("unchecked") @Override protected void add(InstancerKey key, IndirectInstancer instancer, Model model, RenderStage stage) { + if (model.meshes() + .isEmpty()) { + // Don't bother allocating resources for models with no meshes. + return; + } + var group = (IndirectCullingGroup) cullingGroups.computeIfAbsent(key.type(), IndirectCullingGroup::new); group.add((IndirectInstancer) instancer, model, stage); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedDrawManager.java b/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedDrawManager.java index af2810ff9..9901ab354 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedDrawManager.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedDrawManager.java @@ -65,6 +65,12 @@ public class InstancedDrawManager extends InstancerStorage @Override protected void add(InstancerKey key, InstancedInstancer instancer, Model model, RenderStage stage) { + if (model.meshes() + .isEmpty()) { + // Don't bother allocating resources for models with no meshes. + return; + } + instancer.init(); DrawSet drawSet = drawSets.computeIfAbsent(stage, DrawSet::new); diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 88c8b8d20..366b6e035 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -30,8 +30,10 @@ ordering = "NONE" side = "CLIENT" [[dependencies.flywheel]] -modId = "embeddium" +modId = "rubidium" mandatory = false -versionRange = "${embeddium_version_range}" +# This should be a "breaks" dependency. +# There's a mixin crash with Rubidum < 0.7.0 +versionRange = "[0.7.0,)" ordering = "NONE" side = "CLIENT"