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);
|
||||
const float intensity = kTotalSceneLightIntensityCandela / lights_.size();
|
||||
for (auto& light : lights_) {
|
||||
light->SetIntensity(light->IsHeadlight() ? kHeadlightIntensityCandela
|
||||
: intensity);
|
||||
if (light) {
|
||||
light->SetIntensity(light->IsHeadlight() ? kHeadlightIntensityCandela
|
||||
: intensity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -381,9 +383,11 @@ void SceneView::UpdateScene(const mjrContext* context, const mjvScene* scene) {
|
||||
continue;
|
||||
} else if (scene_light.id < lights_.size() - 1) {
|
||||
std::unique_ptr<Light>& light = lights_[scene_light.id];
|
||||
light->SetColor(ReadFloat3(scene_light.diffuse));
|
||||
light->SetTransform(ReadFloat3(scene_light.pos),
|
||||
ReadFloat3(scene_light.dir));
|
||||
if (light) {
|
||||
light->SetColor(ReadFloat3(scene_light.diffuse));
|
||||
light->SetTransform(ReadFloat3(scene_light.pos),
|
||||
ReadFloat3(scene_light.dir));
|
||||
}
|
||||
} else {
|
||||
mju_error("Unexpected light id: %d", scene_light.id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user