Page MenuHome

Fix: Viewport stats not fully working for Geometry Nodes
ClosedPublic

Authored by Erik Abrahamsson (erik85) on Oct 3 2021, 6:54 PM.

Details

Summary

In some cases geometry created in Geometry Nodes will not be counted properly in the viewport stats.
This seems to be because the object runtime data is not filled for those meshes when only used for instances.

(I chose Brecht as reviewer because I saw that he modified that part of the file earlier)

Also if it's accepted please commit because I have no rights.

Before:

After:

Diff Detail

Repository
rB Blender

Event Timeline

Erik Abrahamsson (erik85) requested review of this revision.Oct 3 2021, 6:54 PM
Erik Abrahamsson (erik85) created this revision.
Brecht Van Lommel (brecht) requested changes to this revision.Oct 4 2021, 11:55 AM

We have calls to BKE_object_get_evaluated_mesh in many places, it's a bit weak that this works most of the time but not for depsgraph iterators. If we fix just this case it's easy to get the same bug in other places, now or in the future.

I'm thinking that setting object->runtime.data_eval in the depsgraph iterator could work, so that BKE_object_get_evaluated_mesh returns the correct mesh. But I have not tested and not sure if @Jacques Lucke (JacquesLucke) has some opinion on this.

This revision now requires changes to proceed.Oct 4 2021, 11:55 AM

This change seems to work in my tests:

diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 2f3b229a180..d1b30ff5519 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -5763,7 +5763,7 @@ void BKE_object_replace_data_on_shallow_copy(Object *ob, ID *new_data)
   ob->type = BKE_object_obdata_to_type(new_data);
   ob->data = new_data;
   ob->runtime.geometry_set_eval = NULL;
-  ob->runtime.data_eval = NULL;
+  ob->runtime.data_eval = new_data;
   if (ob->runtime.bb != NULL) {
     ob->runtime.bb->flag |= BOUNDBOX_DIRTY;
   }

Hard to say if this breaks anything else. But if we test it in a couple production files and on the different object types, it may be safe enough.

Updated with the fix suggested by Jacques to be able to run tests on buildbot.

Erik asked me to run the tests on the buildbot with this patch: https://builder.blender.org/admin/#/builders/18/builds/154

I started it in debug mode.

Code looks fine to me, though not sure why the tests are failing on some platforms.

This revision is now accepted and ready to land.Nov 5 2021, 1:45 PM

I think another fix might be removing this line:

ob->runtime.geometry_set_eval = NULL;

I didn't test that though.

That wouldn't work, here we are creating an object that has a specific type. It shouldn't have multiple geometries.

Ah, okay, right. That makes sense. This makes sense to me too then.

Code looks fine to me, though not sure why the tests are failing on some platforms.

It was probably a temporary thing with the buildbot. It succeeded on the second try: https://builder.blender.org/admin/#/builders/18/builds/157

@Erik Abrahamsson (erik85) you can commit this to the blender-v3.0-release branch.