Page MenuHome

Mesh: Move runtime data out of DNA
ClosedPublic

Authored by Hans Goudey (HooglyBoogly) on Oct 7 2022, 5:51 AM.

Details

Summary

This commit replaces the Mesh_Runtime struct embedded in Mesh
with blender::bke::MeshRuntime. This has quite a few benefits:

  • It's possible to use C++ types like std::mutex, Array, BitVector, etc. more easily
  • Meshes saved in files are slightly smaller
  • Copying and writing meshes is a bit more obvious without clearing of runtime data, etc.

The first is by far the most important though. It will allows us to avoid a bunch
of manual memory management boilerplate that is error-prone and annoying.
It should also simplify future CoW improvements for runtime data.

This patch doesn't change anything besides changing mesh.runtime.data to
mesh.runtime->data. The cleanups above will happen in separate commits.

Diff Detail

Repository
rB Blender

Event Timeline

Hans Goudey (HooglyBoogly) requested review of this revision.Oct 7 2022, 5:51 AM
Hans Goudey (HooglyBoogly) updated this revision to Diff 56573.
Hans Goudey (HooglyBoogly) created this revision.

Cleanup stray semicolon

Campbell Barton (campbellbarton) requested changes to this revision.Oct 7 2022, 6:36 AM

Running into crash entering edit-mode on the default cube on the factory startup (Mesh.runtime is NULL): P3242

Besides the NULL state of runtime being resolved, I don't see issue with the patch, although the tests should be run on this (if you didn't already).

source/blender/makesdna/DNA_mesh_types.h
204

Checking over the code, it seems this is expected to be allocated (no need to NULL check the value), for meshes in Main.

It would be good to note this in a code-comment, also if there are any cases where it will be NULL at run-time - that should be mentioned too.

This revision now requires changes to proceed.Oct 7 2022, 6:36 AM
Hans Goudey (HooglyBoogly) marked an inline comment as done.
  • Add comment about runtime data in DNA
  • Fix issue with null runtime data for undo meshes

Thanks for the review. Tests are passing here.

Campbell Barton (campbellbarton) added inline comments.
source/blender/makesdna/DNA_mesh_types.h
207

This "should" doesn't inspire confidence, example for alternate wording.

Run-time data is ensured to be non-null on file-load and can be accessed without NULL checks.
An exception to this is temporary meshes which should allocate and free the data if the meshes are passed to functions that expect run-time data.
This revision is now accepted and ready to land.Oct 13 2022, 2:05 AM
This revision was automatically updated to reflect the committed changes.