Page MenuHome

Fixed crash when adding/removing custom normals from pinned mesh
ClosedPublic

Authored by Sybren A. Stüvel (sybren) on Jul 11 2019, 10:35 AM.

Details

Summary

When a mesh is pinned in the properties panel, Blender crashes when you click the "Add Custom Split Normals Data".

The code calls ob = ED_object_context(C) which returns NULL when the mesh is pinned in the properties panel, causing a segfault when trying to get the mesh via ob->data.

A new function ED_mesh_context(C) avoids this by first checking whether a mesh was pinned in the context. If not, it checks the pinned object's data. If that's not there, or it's not a mesh, it returns the active object's mesh. Finally it returns NULL if there is no active object, or if the active object is not a mesh object.

Diff Detail

Repository
rB Blender

Event Timeline

Brecht Van Lommel (brecht) requested changes to this revision.Jul 11 2019, 12:28 PM
Brecht Van Lommel (brecht) added inline comments.
source/blender/editors/mesh/mesh_data.c
1293–1298

Use Mesh *mesh = CTX_data_pointer_get_type(C, "mesh", &RNA_Mesh).data; so it goes through the context system instead of being hardcoded for the properties editor.

This revision now requires changes to proceed.Jul 11 2019, 12:28 PM
Sybren A. Stüvel (sybren) updated this revision to Diff 16335.
  • Using CTX_data_pointer_get_type() as per Brecht's comment

The context system is still magic to me. Where can I find more info?
How could I have figured out by myself that there apparently is a
"mesh" in the context, and that this takes the pinned ID into account?

Sybren A. Stüvel (sybren) marked an inline comment as done.Jul 12 2019, 10:28 AM

Documentation on context is here:
https://archive.blender.org/wiki/index.php/Dev:2.5/Source/Architecture/Context/

Basically you'd need to be aware that each editor has a context callback, and then look in the properties editor context callback to see what's in there.

This revision is now accepted and ready to land.Jul 14 2019, 6:27 PM

Thanks for the info; I've copied that page to the new wiki.