From 6b93a2d364597d070821bb155ce3a384c21e52dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 2 Nov 2020 16:39:28 +0100 Subject: [PATCH] ShaderTools: fix the input callback snippet to be less wrong. First of all, it's quite unusual to have an array of const chars. Then, it was not really handling file opening errors, which is actually a VERY BAD THING when you are wondering why your include isn't parsed. --- doc/snippets/MagnumShaderTools.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/doc/snippets/MagnumShaderTools.cpp b/doc/snippets/MagnumShaderTools.cpp index 12b91c6cb..3eeff6612 100644 --- a/doc/snippets/MagnumShaderTools.cpp +++ b/doc/snippets/MagnumShaderTools.cpp @@ -97,11 +97,10 @@ Containers::Array spirv = converter->convertDataToData( { Containers::Pointer converter; -Containers::Array extract(const std::string&, const std::string&); +Containers::Array extract(const std::string&, const std::string&); /* [AbstractConverter-usage-callbacks] */ struct Data { - std::unordered_map> files; + std::unordered_map> files; } data; converter->setInputFileCallback([](const std::string& filename, @@ -116,11 +115,16 @@ converter->setInputFileCallback([](const std::string& filename, return {}; } - /* Extract from an archive if not there yet */ - if(found == data.files.end()) found = data.files.emplace( - filename, extract("shaders.zip", filename)).first; + /* Extract from an archive if not there yet; fail if not extraction + failed */ + if(found == data.files.end()) { + Containers::Array file = extract("shaders.zip", filename); + if(!file) return {}; - return Containers::arrayView(found->second); + found = data.files.emplace(filename, std::move(file)).first; + } + + return Containers::ArrayView{found->second}; }, data); /* extracted from a ZIP */