diff options
author | Zolnai Tamás <tamas.zolnai@collabora.com> | 2014-05-20 16:46:43 +0200 |
---|---|---|
committer | Zolnai Tamás <tamas.zolnai@collabora.com> | 2014-05-21 15:25:08 +0200 |
commit | d1711bb430b68e2a0ac2eb86efc998cf6a152b4a (patch) | |
tree | de947f236e93d0f09218e20c942ceedca3652cd4 /avmedia/source | |
parent | ee734562dfb36ed1025bfe8a4bfd4eece2c53533 (diff) |
glTF embedding: handle missing image on a better way
Using empty tree leads to empty image url which
cause problem.
Change-Id: If815ce588fb303905035185404ede93fa424fcba
Diffstat (limited to 'avmedia/source')
-rw-r--r-- | avmedia/source/framework/modeltools.cxx | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/avmedia/source/framework/modeltools.cxx b/avmedia/source/framework/modeltools.cxx index 2366dc756e4a..66a95b31e9d2 100644 --- a/avmedia/source/framework/modeltools.cxx +++ b/avmedia/source/framework/modeltools.cxx @@ -25,6 +25,7 @@ #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/json_parser.hpp> #include <boost/foreach.hpp> +#include <boost/optional.hpp> #ifdef ENABLE_COLLADA2GLTF #include <COLLADA2GLTFWriter.h> @@ -71,7 +72,7 @@ static void lcl_EmbedExternals(const OUString& rSourceURL, uno::Reference<embed: // Parse json, read externals' URI and modify this relative URI's so they remain valid in the new context. std::vector<std::string> vExternals; - ptree aTree, aEmptyTree; + ptree aTree; try { json_parser::read_json( sUrl, aTree ); @@ -85,12 +86,19 @@ static void lcl_EmbedExternals(const OUString& rSourceURL, uno::Reference<embed: aTree.put("buffers." + rVal.first + ".path.",sBufferUri.substr(sBufferUri.find_last_of('/')+1)); } // Images for textures - BOOST_FOREACH(ptree::value_type &rVal,aTree.get_child("images", aEmptyTree)) + boost::optional< ptree& > aImages = aTree.get_child_optional("images"); + if( aImages ) { - const std::string sImageUri(rVal.second.get<std::string>("path")); - vExternals.push_back(sImageUri); - // Change path: make it contain only a file name - aTree.put("images." + rVal.first + ".path.",sImageUri.substr(sImageUri.find_last_of('/')+1)); + BOOST_FOREACH(ptree::value_type &rVal,aImages.get()) + { + const std::string sImageUri(rVal.second.get<std::string>("path")); + if( !sImageUri.empty() ) + { + vExternals.push_back(sImageUri); + // Change path: make it contain only a file name + aTree.put("images." + rVal.first + ".path.",sImageUri.substr(sImageUri.find_last_of('/')+1)); + } + } } // Shaders (contains names only) BOOST_FOREACH(ptree::value_type &rVal,aTree.get_child("programs")) |