From 9415380b4cd3cd88ab4e5784c9413bb06ceef968 Mon Sep 17 00:00:00 2001 From: CwTCwT Date: Sun, 10 Jun 2018 10:35:15 +0200 Subject: [PATCH] usage of dynamic_cast instead of static_cast --- code/BlenderCustomData.cpp | 10 ++++++---- code/BlenderCustomData.h | 4 ++-- code/BlenderLoader.cpp | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/code/BlenderCustomData.cpp b/code/BlenderCustomData.cpp index 434a2c60b..682186618 100644 --- a/code/BlenderCustomData.cpp +++ b/code/BlenderCustomData.cpp @@ -24,11 +24,11 @@ namespace Assimp { */ typedef bool (*PRead)(ElemBase *pOut, const size_t cnt, const FileDatabase &db); typedef ElemBase * (*PCreate)(const size_t cnt); - typedef void (*PDestroy)(ElemBase *); + typedef void(*PDestroy)(ElemBase *); #define IMPL_STRUCT_READ(ty) \ bool read##ty(ElemBase *v, const size_t cnt, const FileDatabase &db) { \ - return read(db.dna[#ty], static_cast(v), cnt, db); \ + return read(db.dna[#ty], dynamic_cast(v), cnt, db); \ } #define IMPL_STRUCT_CREATE(ty) \ @@ -37,7 +37,8 @@ namespace Assimp { } #define IMPL_STRUCT_DESTROY(ty) \ - void destroy##ty(ElemBase *p) { \ + void destroy##ty(ElemBase *pE) { \ + ty *p = dynamic_cast(pE); \ delete[]p; \ } @@ -172,7 +173,8 @@ namespace Assimp { return nullptr; } - const void * getCustomDataLayerData(const CustomData &customdata, const CustomDataType cdtype, const std::string &name) { + const ElemBase * getCustomDataLayerData(const CustomData &customdata, const CustomDataType cdtype, const std::string &name) + { const std::shared_ptr pLayer = getCustomDataLayer(customdata, cdtype, name); if (pLayer && pLayer->data) { return pLayer->data.get(); diff --git a/code/BlenderCustomData.h b/code/BlenderCustomData.h index 879f40159..f61d79a26 100644 --- a/code/BlenderCustomData.h +++ b/code/BlenderCustomData.h @@ -82,8 +82,8 @@ namespace Assimp { * @param[in] customdata CustomData to search for wanted layer * @param[in] cdtype to search for * @param[in] name to search for - * @return CustomDataLayer * or nullptr if not found + * @return * to struct data or nullptr if not found */ - const void * getCustomDataLayerData(const CustomData &customdata, CustomDataType cdtype, const std::string &name); + const ElemBase * getCustomDataLayerData(const CustomData &customdata, CustomDataType cdtype, const std::string &name); } } diff --git a/code/BlenderLoader.cpp b/code/BlenderLoader.cpp index a463808cf..30aafc705 100644 --- a/code/BlenderLoader.cpp +++ b/code/BlenderLoader.cpp @@ -1039,9 +1039,9 @@ void BlenderImporter::ConvertMesh(const Scene& /*in*/, const Object* /*obj*/, co for (uint32_t t = 0; t < maxTex; ++t) { if (pMat->mtex[t] && pMat->mtex[t]->uvname[0]) { // get the CustomData layer for given uvname and correct type - const MLoopUV *pLoop = static_cast(getCustomDataLayerData(mesh->ldata, CD_MLOOPUV, pMat->mtex[t]->uvname)); + const ElemBase *pLoop = getCustomDataLayerData(mesh->ldata, CD_MLOOPUV, pMat->mtex[t]->uvname); if (pLoop) { - texuv.insert(std::make_pair(t, pLoop)); + texuv.insert(std::make_pair(t, dynamic_cast(pLoop))); } } }