Fix crash when using image-based textures.
Image lights are not normal lights, so use nullptr as a placeholder. Add checks for nullness when iterating over the lights. PiperOrigin-RevId: 840695579 Change-Id: I092515ae814523e85f4f5ce87b2bac2241f4ea35
This commit is contained in:
committed by
Copybara-Service
parent
6e7b2ba4c3
commit
fcdacd0690
@@ -327,8 +327,10 @@ void SceneView::PrepareLights() {
|
|||||||
SetFallbackEnvironmentLight(kFallbackEnvironmentLightIntensityCandela);
|
SetFallbackEnvironmentLight(kFallbackEnvironmentLightIntensityCandela);
|
||||||
const float intensity = kTotalSceneLightIntensityCandela / lights_.size();
|
const float intensity = kTotalSceneLightIntensityCandela / lights_.size();
|
||||||
for (auto& light : lights_) {
|
for (auto& light : lights_) {
|
||||||
light->SetIntensity(light->IsHeadlight() ? kHeadlightIntensityCandela
|
if (light) {
|
||||||
: intensity);
|
light->SetIntensity(light->IsHeadlight() ? kHeadlightIntensityCandela
|
||||||
|
: intensity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -381,9 +383,11 @@ void SceneView::UpdateScene(const mjrContext* context, const mjvScene* scene) {
|
|||||||
continue;
|
continue;
|
||||||
} else if (scene_light.id < lights_.size() - 1) {
|
} else if (scene_light.id < lights_.size() - 1) {
|
||||||
std::unique_ptr<Light>& light = lights_[scene_light.id];
|
std::unique_ptr<Light>& light = lights_[scene_light.id];
|
||||||
light->SetColor(ReadFloat3(scene_light.diffuse));
|
if (light) {
|
||||||
light->SetTransform(ReadFloat3(scene_light.pos),
|
light->SetColor(ReadFloat3(scene_light.diffuse));
|
||||||
ReadFloat3(scene_light.dir));
|
light->SetTransform(ReadFloat3(scene_light.pos),
|
||||||
|
ReadFloat3(scene_light.dir));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
mju_error("Unexpected light id: %d", scene_light.id);
|
mju_error("Unexpected light id: %d", scene_light.id);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user