Fix #146529: Crash getting RNA path to scene rigid body pointcache

Spawning the tooltip or changing values would cause this.

Error in 28827b62f7

Above commit only considered PointCaches associated with **objects**,
not taking into account scene rigid body cache.
This is now added with this PR.
Previously it would cast into modifiers when we actually had a scene as
owner... resulting in a crash.

This was only exposed by 6bf8685628 (it crashes since, was just not
working properly before...). 6bf8685628 changed the data layout of
`struct Object` and only by pure luck the modifiers loop was skipped, now
with the new layout it is entered (but with garbage data resulting in the crash.

Pull Request: https://projects.blender.org/blender/blender/pulls/146577
This commit is contained in:
Philipp Oeser
2025-10-06 09:38:39 +02:00
committed by Philipp Oeser
parent 6ffd9be9a6
commit 47a0d9b52f

View File

@@ -118,7 +118,7 @@ static const EnumPropertyItem empty_vortex_shape_items[] = {
# include "ED_object.hh"
static bool rna_Cache_get_valid_owner_ID(PointerRNA *ptr, Object **ob, Scene **scene)
static bool rna_Cache_get_valid_owner_ID(const PointerRNA *ptr, Object **ob, Scene **scene)
{
switch (GS(ptr->owner_id->name)) {
case ID_OB:
@@ -139,10 +139,27 @@ static bool rna_Cache_get_valid_owner_ID(PointerRNA *ptr, Object **ob, Scene **s
static std::optional<std::string> rna_PointCache_path(const PointerRNA *ptr)
{
ModifierData *md;
Object *ob = (Object *)ptr->owner_id;
PointCache *cache = static_cast<PointCache *>(ptr->data);
Object *ob = nullptr;
Scene *scene = nullptr;
if (!rna_Cache_get_valid_owner_ID(ptr, &ob, &scene)) {
return std::nullopt;
}
/* Scene rigid body. */
if (scene != nullptr && scene->rigidbody_world->shared != nullptr) {
if (scene->rigidbody_world->shared->pointcache == cache) {
return "rigidbody_world.point_cache";
}
}
if (!ob) {
return std::nullopt;
}
ModifierData *md;
for (md = static_cast<ModifierData *>(ob->modifiers.first); md; md = md->next) {
const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(md->type));
@@ -198,6 +215,7 @@ static std::optional<std::string> rna_PointCache_path(const PointerRNA *ptr)
}
}
}
return std::nullopt;
}