Merge pull request #40628 from reduz/fix-dynamic-light-crash

Fixes RenderingServer crashes reported by #39951
This commit is contained in:
Rémi Verschelde 2020-07-23 13:13:37 +02:00 committed by GitHub
commit dfdc48a9de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 6 deletions

View File

@ -370,8 +370,8 @@ void RenderingServerScene::instance_set_base(RID p_instance, RID p_base) {
case RS::INSTANCE_LIGHT: { case RS::INSTANCE_LIGHT: {
InstanceLightData *light = static_cast<InstanceLightData *>(instance->base_data); InstanceLightData *light = static_cast<InstanceLightData *>(instance->base_data);
if (RSG::storage->light_get_type(instance->base) != RS::LIGHT_DIRECTIONAL && light->bake_mode == RS::LIGHT_BAKE_DYNAMIC) { if (scenario && RSG::storage->light_get_type(instance->base) != RS::LIGHT_DIRECTIONAL && light->bake_mode == RS::LIGHT_BAKE_DYNAMIC) {
instance->scenario->dynamic_lights.erase(light->instance); scenario->dynamic_lights.erase(light->instance);
} }
#ifdef DEBUG_ENABLED #ifdef DEBUG_ENABLED
@ -379,8 +379,8 @@ void RenderingServerScene::instance_set_base(RID p_instance, RID p_base) {
ERR_PRINT("BUG, indexing did not unpair geometries from light."); ERR_PRINT("BUG, indexing did not unpair geometries from light.");
} }
#endif #endif
if (instance->scenario && light->D) { if (scenario && light->D) {
instance->scenario->directional_lights.erase(light->D); scenario->directional_lights.erase(light->D);
light->D = nullptr; light->D = nullptr;
} }
RSG::scene_render->free(light->instance); RSG::scene_render->free(light->instance);
@ -986,13 +986,13 @@ void RenderingServerScene::_update_instance(Instance *p_instance) {
RS::LightBakeMode bake_mode = RSG::storage->light_get_bake_mode(p_instance->base); RS::LightBakeMode bake_mode = RSG::storage->light_get_bake_mode(p_instance->base);
if (RSG::storage->light_get_type(p_instance->base) != RS::LIGHT_DIRECTIONAL && bake_mode != light->bake_mode) { if (RSG::storage->light_get_type(p_instance->base) != RS::LIGHT_DIRECTIONAL && bake_mode != light->bake_mode) {
if (light->bake_mode == RS::LIGHT_BAKE_DYNAMIC) { if (p_instance->scenario && light->bake_mode == RS::LIGHT_BAKE_DYNAMIC) {
p_instance->scenario->dynamic_lights.erase(light->instance); p_instance->scenario->dynamic_lights.erase(light->instance);
} }
light->bake_mode = bake_mode; light->bake_mode = bake_mode;
if (light->bake_mode == RS::LIGHT_BAKE_DYNAMIC) { if (p_instance->scenario && light->bake_mode == RS::LIGHT_BAKE_DYNAMIC) {
p_instance->scenario->dynamic_lights.push_back(light->instance); p_instance->scenario->dynamic_lights.push_back(light->instance);
} }
} }