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.
This commit is contained in:
Jozufozu 2024-01-16 16:59:15 -08:00
parent de622ccc51
commit ad27133253
4 changed files with 36 additions and 2 deletions

View file

@ -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<N extends AbstractInstancer<?>> {
return (Instancer<I>) 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<N extends AbstractInstancer<?>> {
}
}
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();

View file

@ -46,6 +46,12 @@ public class IndirectDrawManager extends InstancerStorage<IndirectInstancer<?>>
@SuppressWarnings("unchecked")
@Override
protected <I extends Instance> void add(InstancerKey<I> 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<I>) cullingGroups.computeIfAbsent(key.type(), IndirectCullingGroup::new);
group.add((IndirectInstancer<I>) instancer, model, stage);
}

View file

@ -65,6 +65,12 @@ public class InstancedDrawManager extends InstancerStorage<InstancedInstancer<?>
@Override
protected <I extends Instance> void add(InstancerKey<I> 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);

View file

@ -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"