Quellcode durchsuchen

Update HMPLoader.cpp

- Fix possible division by zero
- closes https://github.com/assimp/assimp/issues/4235
Kim Kulling vor 3 Jahren
Ursprung
Commit
33c6762272
1 geänderte Dateien mit 11 neuen und 5 gelöschten Zeilen
  1. 11 5
      code/AssetLib/HMP/HMPLoader.cpp

+ 11 - 5
code/AssetLib/HMP/HMPLoader.cpp

@@ -473,16 +473,22 @@ void HMPImporter::ReadFirstSkin(unsigned int iNumSkins, const unsigned char *szC
 
 // ------------------------------------------------------------------------------------------------
 // Generate proepr texture coords
-void HMPImporter::GenerateTextureCoords(
-        const unsigned int width, const unsigned int height) {
+void HMPImporter::GenerateTextureCoords(const unsigned int width, const unsigned int height) {
     ai_assert(nullptr != pScene->mMeshes);
     ai_assert(nullptr != pScene->mMeshes[0]);
     ai_assert(nullptr != pScene->mMeshes[0]->mTextureCoords[0]);
 
     aiVector3D *uv = pScene->mMeshes[0]->mTextureCoords[0];
-
-    const float fY = (1.0f / height) + (1.0f / height) / (height - 1);
-    const float fX = (1.0f / width) + (1.0f / width) / (width - 1);
+    if (uv == nullptr) {
+        return;
+    }
+    
+    if (height == 0.0f || width == 0.0) {
+        return;
+    }
+    
+    const float fY = (1.0f / height) + (1.0f / height) / height;
+    const float fX = (1.0f / width) + (1.0f / width) / width;
 
     for (unsigned int y = 0; y < height; ++y) {
         for (unsigned int x = 0; x < width; ++x, ++uv) {