STL-Exporter: fix division by zero in normalize method during update

This commit is contained in:
Kim Kulling
2018-05-01 15:06:56 +02:00
parent eced86b949
commit 037a213bb4
5 changed files with 53 additions and 29 deletions

View File

@@ -115,8 +115,14 @@ public:
}
};
public:
/**
* @brief The class constructor.
*/
Exporter();
/**
* @brief The class destructor.
*/
~Exporter();
// -------------------------------------------------------------------

View File

@@ -46,15 +46,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/Importer.hpp>
#include <assimp/ai_assert.h>
#include "Hash.h"
#include <map>
#include <map>
// ------------------------------------------------------------------------------------------------
template <class T>
inline bool SetGenericProperty(std::map< unsigned int, T >& list,
const char* szName, const T& value)
{
ai_assert(NULL != szName);
inline
bool SetGenericProperty(std::map< unsigned int, T >& list,
const char* szName, const T& value) {
ai_assert(nullptr != szName);
const uint32_t hash = SuperFastHash(szName);
typename std::map<unsigned int, T>::iterator it = list.find(hash);
@@ -63,20 +63,22 @@ inline bool SetGenericProperty(std::map< unsigned int, T >& list,
return false;
}
(*it).second = value;
return true;
}
// ------------------------------------------------------------------------------------------------
template <class T>
inline const T& GetGenericProperty(const std::map< unsigned int, T >& list,
const char* szName, const T& errorReturn)
{
ai_assert(NULL != szName);
inline
const T& GetGenericProperty(const std::map< unsigned int, T >& list,
const char* szName, const T& errorReturn) {
ai_assert(nullptr != szName);
const uint32_t hash = SuperFastHash(szName);
typename std::map<unsigned int, T>::const_iterator it = list.find(hash);
if (it == list.end())
if (it == list.end()) {
return errorReturn;
}
return (*it).second;
}
@@ -85,16 +87,17 @@ inline const T& GetGenericProperty(const std::map< unsigned int, T >& list,
// Special version for pointer types - they will be deleted when replaced with another value
// passing NULL removes the whole property
template <class T>
inline void SetGenericPropertyPtr(std::map< unsigned int, T* >& list,
const char* szName, T* value, bool* bWasExisting = NULL)
{
ai_assert(NULL != szName);
inline
void SetGenericPropertyPtr(std::map< unsigned int, T* >& list,
const char* szName, T* value, bool* bWasExisting = nullptr ) {
ai_assert(nullptr != szName);
const uint32_t hash = SuperFastHash(szName);
typename std::map<unsigned int, T*>::iterator it = list.find(hash);
if (it == list.end()) {
if (bWasExisting)
if (bWasExisting) {
*bWasExisting = false;
}
list.insert(std::pair<unsigned int,T*>( hash, value ));
return;
@@ -106,20 +109,23 @@ inline void SetGenericPropertyPtr(std::map< unsigned int, T* >& list,
if (!value) {
list.erase(it);
}
if (bWasExisting)
if (bWasExisting) {
*bWasExisting = true;
}
}
// ------------------------------------------------------------------------------------------------
template <class T>
inline bool HasGenericProperty(const std::map< unsigned int, T >& list,
const char* szName)
{
ai_assert(NULL != szName);
inline
bool HasGenericProperty(const std::map< unsigned int, T >& list,
const char* szName) {
ai_assert(nullptr != szName);
const uint32_t hash = SuperFastHash(szName);
typename std::map<unsigned int, T>::const_iterator it = list.find(hash);
if (it == list.end()) return false;
if (it == list.end()) {
return false;
}
return true;
}