From c01b102f54770c37a62870f60a849b479aa3285c Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 25 Apr 2018 13:51:53 +0300 Subject: [PATCH] Throw key_error if an inherited Technique uses nonexistent texture slot --- source/technique.cpp | 16 +++++++++++----- source/technique.h | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/source/technique.cpp b/source/technique.cpp index 2b02f35f..def0a84a 100644 --- a/source/technique.cpp +++ b/source/technique.cpp @@ -28,15 +28,20 @@ const RenderPass &Technique::get_pass(const Tag &tag) const return get_item(passes, tag); } -void Technique::replace_texture(const string &slot, const Texture &tex) +bool Technique::replace_texture(const string &slot, const Texture &tex) { + bool replaced = false; for(PassMap::iterator i=passes.begin(); i!=passes.end(); ++i) { int index = i->second.get_texture_index(slot); - if(index<0) - continue; - i->second.set_texture(index, &tex); + if(index>=0) + { + i->second.set_texture(index, &tex); + replaced = true; + } } + + return replaced; } bool Technique::has_shaders() const @@ -108,7 +113,8 @@ void Technique::InheritLoader::material(const string &pass_tag, const string &na void Technique::InheritLoader::texture(const string &slot, const string &name) { - obj.replace_texture(slot, get_collection().get(name)); + if(!obj.replace_texture(slot, get_collection().get(name))) + throw key_error(slot); } } // namespace GL diff --git a/source/technique.h b/source/technique.h index 7ea69537..bed1db33 100644 --- a/source/technique.h +++ b/source/technique.h @@ -50,7 +50,7 @@ public: bool has_pass(const Tag &) const; const RenderPass &get_pass(const Tag &) const; const PassMap &get_passes() const { return passes; } - void replace_texture(const std::string &, const Texture &); + bool replace_texture(const std::string &, const Texture &); bool has_shaders() const; }; -- 2.43.0