From 420555c69c982def7afd4bb69387d20e48ea319d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Garc=C3=ADa=20Li=C3=B1=C3=A1n?= Date: Sat, 24 Jul 2021 19:47:09 +0200 Subject: [PATCH] Fix issue with Effect techniques that have the highest index and a scheme We previously used the last technique, but now we use the last technique that has no scheme. --- simgear/scene/material/Effect.cxx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/simgear/scene/material/Effect.cxx b/simgear/scene/material/Effect.cxx index d0b648ef..47af7ed2 100644 --- a/simgear/scene/material/Effect.cxx +++ b/simgear/scene/material/Effect.cxx @@ -240,11 +240,19 @@ Effect::Effect(const Effect& rhs, const CopyOp& copyop) _name += " clone"; } -// Assume that the last technique is always valid. +// Try to use the state set of the last technique without a scheme. StateSet* Effect::getDefaultStateSet() { - Technique* tniq = techniques.back().get(); - if (!tniq) + if (techniques.empty()) + return 0; + auto it = std::find_if(techniques.rbegin(), techniques.rend(), + [](const osg::ref_ptr &t) { + return t && t->getScheme().empty(); + }); + if (it == techniques.rend()) + return 0; + Technique* tniq = (*it); + if (tniq->passes.empty()) return 0; Pass* pass = tniq->passes.front().get(); return pass;