Page MenuHome

Fix T91518: crash when recalculating looptris after clearing geometry.
ClosedPublic

Authored by Jeroen Bakker (jbakker) on Nov 8 2021, 12:18 PM.

Details

Summary

When clearing geometry the runtime mutexes of a mesh were freed. This
resulted in crashes afterwards. The clear geometry is an RNA function so
would only effect when using from scripts.

This patch separates init/freeing of the mutexes from other code so they
can be used when needed.

Diff Detail

Repository
rB Blender

Event Timeline

Jeroen Bakker (jbakker) requested review of this revision.Nov 8 2021, 12:18 PM
Jeroen Bakker (jbakker) created this revision.
Bastien Montagne (mont29) requested changes to this revision.Nov 8 2021, 4:16 PM

Besides actual mistakes and inconsistencies noted in comments below, in general for me this change adds even more confusion to this 'runtime management' area of the code...

From what I understand, the issue here is that BKE_mesh_runtime_clear_cache (unexpectedly) also clears the mutexes? Then I would simply add a new BKE_mesh_runtime_clear superseding function, that does clear mutexes and then call BKE_mesh_runtime_clear_cache, that clears everything in runtime besides the mutexes. BKE_mesh_runtime_clear would be used from mesh_free_data, while BKE_mesh_runtime_clear_cache would be used from BKE_mesh_clear_geometry.

Then having (static, private) helpers to factorize out mutexes handling would be good indeed, although I would only have create and free ones tbh, the reset one does not seem really necessary here?

This would also need comments to properly document what is expected behaviors/roles of all those functions.

source/blender/blenkernel/intern/mesh_runtime.c
111

This has nothing to do here? You create a set of functions dedicated to mutexes, but then wipe out the entire runtime struct in them?

121–125

This also has nothing to do in a mutexes specific function.

151

Calling this here effectively wipes out the entire runtime struct, which is exactly what we do not want to do here...

This revision now requires changes to proceed.Nov 8 2021, 4:16 PM
  • Use init_data/free_data convention for mesh runtime initialization.
Jeroen Bakker (jbakker) marked 3 inline comments as done.
  • Remove redundant call.
Jeroen Bakker (jbakker) planned changes to this revision.Nov 9 2021, 2:45 PM

You're right there were some bugs in the patch.

After trying some different approaches I moved the clearing of the runtime struct to the read_file of mesh and use init_data/free_data as higher level API.

source/blender/blenkernel/intern/mesh.c
171

Can be removed. Is also called from within BKE_mesh_runtime_free_data

Jeroen Bakker (jbakker) requested review of this revision.Nov 9 2021, 2:47 PM

LGTM, besides minor remarks below.

source/blender/blenkernel/intern/mesh_runtime.c
52

static functions do not take the module prefix (so just mesh_runtime_init_mutexes)

63

static functions do not take the module prefix (so just mesh_runtime_free_mutexes)

119

Would be nice to add doc to this one too?

This revision is now accepted and ready to land.Nov 9 2021, 2:54 PM
Jeroen Bakker (jbakker) marked 2 inline comments as done.
  • Cleanup: remove prefix from static functions.
  • Cleanup added documentation to BKE_mesh_runtime_clear_cache.