Skip to content

Commit 80096e9

Browse files
jamesmintramakien-mga
authored andcommitted
Fix a crash bug in LightmapGI::_assign_lightmaps triggered after reparenting
After reparenting the LightmapGI node, the following `node` would be initialized to null: Node *node = get_node(light_data->get_user_path(i)); Which would then crash when de-referenced further down. This fix detects which the node has been reparented and clears its users.
1 parent c394eaa commit 80096e9

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

scene/3d/lightmap_gi.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,11 +1491,17 @@ void LightmapGI::_notification(int p_what) {
14911491
"%s (%s): The directional lightmap textures are stored in a format that isn't supported anymore. Please bake lightmaps again to make lightmaps display from this node again.",
14921492
get_light_data()->get_path(), get_name()));
14931493

1494+
if (last_owner && last_owner != get_owner()) {
1495+
light_data->clear_users();
1496+
}
1497+
14941498
_assign_lightmaps();
14951499
}
14961500
} break;
14971501

14981502
case NOTIFICATION_EXIT_TREE: {
1503+
last_owner = get_owner();
1504+
14991505
if (light_data.is_valid()) {
15001506
_clear_lightmaps();
15011507
}

scene/3d/lightmap_gi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ class LightmapGI : public VisualInstance3D {
206206
Ref<CameraAttributes> camera_attributes;
207207

208208
Ref<LightmapGIData> light_data;
209+
Node *last_owner = nullptr;
209210

210211
struct LightsFound {
211212
Transform3D xform;

0 commit comments

Comments
 (0)