From 36127c02e08ee5b1e07abcd3665c3935d1a679b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 8 Jun 2022 12:52:47 +0200 Subject: [PATCH] AnySceneImporter: fix meshAttribute[For]Name() without a file opened. --- doc/changelog.dox | 4 ++++ .../AnySceneImporter/AnySceneImporter.cpp | 12 ++++++++++-- .../AnySceneImporter/AnySceneImporter.h | 4 ++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/doc/changelog.dox b/doc/changelog.dox index 91dce63ff..a542a3f73 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -592,6 +592,10 @@ See also: [mosra/magnum#523](https://github.com/mosra/magnum/issues/523). - `UseEmscripten` is no longer implicitly included on Emscripten as it's not needed for anything (see [mosra/magnum#490](https://github.com/mosra/magnum/issues/490)) +- Fixed an assertion in @relativeref{Trade,AnySceneImporter} when + @relativeref{Trade::AbstractImporter,meshAttributeName()} or + @relativeref{Trade::AbstractImporter,meshAttributeForName()} was called + without a file opened - @ref Trade::ObjImporter "ObjImporter" uses exceptions internally and needs an explicit exception-enabling flag when built with Emscripten 1.39.0 and newer diff --git a/src/MagnumPlugins/AnySceneImporter/AnySceneImporter.cpp b/src/MagnumPlugins/AnySceneImporter/AnySceneImporter.cpp index f816d177c..bc4c09f4f 100644 --- a/src/MagnumPlugins/AnySceneImporter/AnySceneImporter.cpp +++ b/src/MagnumPlugins/AnySceneImporter/AnySceneImporter.cpp @@ -231,8 +231,16 @@ Int AnySceneImporter::doMeshForName(const Containers::StringView name) { return Containers::String AnySceneImporter::doMeshName(const UnsignedInt id) { return _in->meshName(id); } Containers::Optional AnySceneImporter::doMesh(const UnsignedInt id, const UnsignedInt level) { return _in->mesh(id, level); } -MeshAttribute AnySceneImporter::doMeshAttributeForName(const Containers::StringView name) { return _in->meshAttributeForName(name); } -Containers::String AnySceneImporter::doMeshAttributeName(const UnsignedShort id) { return _in->meshAttributeName(meshAttributeCustom(id)); } +MeshAttribute AnySceneImporter::doMeshAttributeForName(const Containers::StringView name) { + /* This API can be called even if no file is opened, in that case return + an invalid ID */ + return _in ? _in->meshAttributeForName(name) : MeshAttribute{}; +} +Containers::String AnySceneImporter::doMeshAttributeName(const UnsignedShort id) { + /* This API can be called even if no file is opened, in that case return + an invalid ID */ + return _in ? _in->meshAttributeName(meshAttributeCustom(id)) : Containers::String{}; +} #ifdef MAGNUM_BUILD_DEPRECATED CORRADE_IGNORE_DEPRECATED_PUSH diff --git a/src/MagnumPlugins/AnySceneImporter/AnySceneImporter.h b/src/MagnumPlugins/AnySceneImporter/AnySceneImporter.h index 44a5bd8aa..262c838b1 100644 --- a/src/MagnumPlugins/AnySceneImporter/AnySceneImporter.h +++ b/src/MagnumPlugins/AnySceneImporter/AnySceneImporter.h @@ -146,6 +146,10 @@ Calls to the @ref animation(), @ref scene(), @ref light(), @ref camera(), and corresponding count-/name-related functions are then proxied to the concrete implementation. The @ref close() function closes and discards the internally instantiated plugin; @ref isOpened() works as usual. + +While the @ref meshAttributeName() and @ref meshAttributeForName() APIs can +be called without a file opened, they return an empty string or an invalid +attribute in that case. */ class MAGNUM_ANYSCENEIMPORTER_EXPORT AnySceneImporter: public AbstractImporter { public: