Exception safety

pull/3329/head
Malcolm Tyrrell 2020-07-15 15:02:27 +01:00
parent 37e1fb9cd7
commit e1bab44e19
2 changed files with 22 additions and 3 deletions

View File

@ -347,7 +347,7 @@ static inline bool CheckValidFacesIndices(aiFace *faces, unsigned nFaces, unsign
void glTF2Importer::ImportMeshes(glTF2::Asset &r) { void glTF2Importer::ImportMeshes(glTF2::Asset &r) {
ASSIMP_LOG_DEBUG_F("Importing ", r.meshes.Size(), " meshes"); ASSIMP_LOG_DEBUG_F("Importing ", r.meshes.Size(), " meshes");
std::vector<aiMesh *> meshes; std::vector<std::unique_ptr<aiMesh>> meshes;
unsigned int k = 0; unsigned int k = 0;
meshOffsets.clear(); meshOffsets.clear();
@ -361,8 +361,8 @@ void glTF2Importer::ImportMeshes(glTF2::Asset &r) {
for (unsigned int p = 0; p < mesh.primitives.size(); ++p) { for (unsigned int p = 0; p < mesh.primitives.size(); ++p) {
Mesh::Primitive &prim = mesh.primitives[p]; Mesh::Primitive &prim = mesh.primitives[p];
aiMesh *aim = new aiMesh(); meshes.emplace_back(std::make_unique<aiMesh>());
meshes.push_back(aim); aiMesh *aim = meshes.back().get();
aim->mName = mesh.name.empty() ? mesh.id : mesh.name; aim->mName = mesh.name.empty() ? mesh.id : mesh.name;

View File

@ -57,6 +57,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <map> #include <map>
#include <set> #include <set>
#include <vector> #include <vector>
#include <memory>
struct aiScene; struct aiScene;
struct aiImporterDesc; struct aiImporterDesc;
@ -391,6 +392,24 @@ public: // static utilities
} }
} }
// -------------------------------------------------------------------
/** Utility function to move a std::vector of unique_ptrs into a aiScene array
* @param vec The vector of unique_ptrs to be moved
* @param out The output pointer to the allocated array.
* @param numOut The output count of elements copied. */
template <typename T>
AI_FORCE_INLINE static void CopyVector(
std::vector<std::unique_ptr<T>> &vec,
T **&out,
unsigned int &outLength) {
outLength = unsigned(vec.size());
if (outLength) {
out = new T*[outLength];
T** outPtr = out;
std::for_each(vec.begin(), vec.end(), [&outPtr](auto& uPtr){*outPtr = uPtr.release(); ++outPtr; });
}
}
protected: protected:
/// Error description in case there was one. /// Error description in case there was one.
std::string m_ErrorText; std::string m_ErrorText;