2020-03-21 06:34:12 +00:00
|
|
|
/*
|
2015-05-19 03:48:29 +00:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
2024-02-23 21:30:05 +00:00
|
|
|
Copyright (c) 2006-2024, assimp team
|
2018-01-28 18:42:05 +00:00
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
All rights reserved.
|
|
|
|
|
2015-05-19 03:52:10 +00:00
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the following
|
2015-05-19 03:48:29 +00:00
|
|
|
conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer in the documentation and/or other
|
|
|
|
materials provided with the distribution.
|
|
|
|
|
|
|
|
* Neither the name of the assimp team, nor the names of its
|
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
|
|
|
written permission of the assimp team.
|
|
|
|
|
2015-05-19 03:52:10 +00:00
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
2015-05-19 03:48:29 +00:00
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
2015-05-19 03:52:10 +00:00
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
2015-05-19 03:48:29 +00:00
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
2015-05-19 03:52:10 +00:00
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
2015-05-19 03:48:29 +00:00
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
2015-05-19 03:52:10 +00:00
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
2015-05-19 03:48:29 +00:00
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file ValidateDataStructure.cpp
|
2015-05-19 03:52:10 +00:00
|
|
|
* @brief Implementation of the post processing step to validate
|
2015-05-19 03:48:29 +00:00
|
|
|
* the data structure returned by Assimp.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// internal headers
|
|
|
|
#include "ValidateDataStructure.h"
|
2020-06-23 19:05:42 +00:00
|
|
|
#include "ProcessHelper.h"
|
2018-01-06 00:18:33 +00:00
|
|
|
#include <assimp/BaseImporter.h>
|
|
|
|
#include <assimp/fast_atof.h>
|
2016-04-05 21:23:53 +00:00
|
|
|
#include <memory>
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
// CRT headers
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
using namespace Assimp;
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Constructor to be privately used by Importer
|
2023-03-14 20:04:43 +00:00
|
|
|
ValidateDSProcess::ValidateDSProcess() : mScene(nullptr) {}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Returns whether the processing step is present in the given flag field.
|
2020-06-23 19:05:42 +00:00
|
|
|
bool ValidateDSProcess::IsActive(unsigned int pFlags) const {
|
2015-05-19 03:57:13 +00:00
|
|
|
return (pFlags & aiProcess_ValidateDataStructure) != 0;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-06-23 19:05:42 +00:00
|
|
|
AI_WONT_RETURN void ValidateDSProcess::ReportError(const char *msg, ...) {
|
|
|
|
ai_assert(nullptr != msg);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
va_list args;
|
2020-06-23 19:05:42 +00:00
|
|
|
va_start(args, msg);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
char szBuffer[3000];
|
2022-10-01 02:03:59 +00:00
|
|
|
const int iLen = vsnprintf(szBuffer, sizeof(szBuffer), msg, args);
|
2015-05-19 03:57:13 +00:00
|
|
|
ai_assert(iLen > 0);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
va_end(args);
|
2017-10-07 17:08:20 +00:00
|
|
|
|
2020-08-18 16:35:08 +00:00
|
|
|
throw DeadlyImportError("Validation failed: ", std::string(szBuffer, iLen));
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-06-23 19:05:42 +00:00
|
|
|
void ValidateDSProcess::ReportWarning(const char *msg, ...) {
|
|
|
|
ai_assert(nullptr != msg);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
va_list args;
|
2020-06-23 19:05:42 +00:00
|
|
|
va_start(args, msg);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
char szBuffer[3000];
|
2022-10-01 02:03:59 +00:00
|
|
|
const int iLen = vsnprintf(szBuffer, sizeof(szBuffer), msg, args);
|
2015-05-19 03:57:13 +00:00
|
|
|
ai_assert(iLen > 0);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
va_end(args);
|
2021-05-13 11:05:31 +00:00
|
|
|
ASSIMP_LOG_WARN("Validation warning: ", std::string(szBuffer, iLen));
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-06-23 19:05:42 +00:00
|
|
|
inline int HasNameMatch(const aiString &in, aiNode *node) {
|
|
|
|
int result = (node->mName == in ? 1 : 0);
|
|
|
|
for (unsigned int i = 0; i < node->mNumChildren; ++i) {
|
|
|
|
result += HasNameMatch(in, node->mChildren[i]);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
return result;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
2020-06-23 19:05:42 +00:00
|
|
|
inline void ValidateDSProcess::DoValidation(T **parray, unsigned int size, const char *firstName, const char *secondName) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// validate all entries
|
2023-05-03 22:00:52 +00:00
|
|
|
if (size == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!parray) {
|
|
|
|
ReportError("aiScene::%s is nullptr (aiScene::%s is %i)",
|
|
|
|
firstName, secondName, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < size; ++i) {
|
|
|
|
if (!parray[i]) {
|
|
|
|
ReportError("aiScene::%s[%i] is nullptr (aiScene::%s is %i)",
|
|
|
|
firstName, i, secondName, size);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2023-05-03 22:00:52 +00:00
|
|
|
Validate(parray[i]);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
2020-06-23 19:05:42 +00:00
|
|
|
inline void ValidateDSProcess::DoValidationEx(T **parray, unsigned int size,
|
|
|
|
const char *firstName, const char *secondName) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// validate all entries
|
2023-05-03 22:00:52 +00:00
|
|
|
if (size == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!parray) {
|
|
|
|
ReportError("aiScene::%s is nullptr (aiScene::%s is %i)",
|
|
|
|
firstName, secondName, size);
|
|
|
|
}
|
|
|
|
for (unsigned int i = 0; i < size; ++i) {
|
|
|
|
if (!parray[i]) {
|
|
|
|
ReportError("aiScene::%s[%u] is nullptr (aiScene::%s is %u)",
|
|
|
|
firstName, i, secondName, size);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2023-05-03 22:00:52 +00:00
|
|
|
Validate(parray[i]);
|
|
|
|
|
|
|
|
// check whether there are duplicate names
|
|
|
|
for (unsigned int a = i + 1; a < size; ++a) {
|
|
|
|
if (parray[i]->mName == parray[a]->mName) {
|
|
|
|
ReportError("aiScene::%s[%u] has the same name as "
|
|
|
|
"aiScene::%s[%u]",
|
|
|
|
firstName, i, secondName, a);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
2020-06-23 19:05:42 +00:00
|
|
|
inline void ValidateDSProcess::DoValidationWithNameCheck(T **array, unsigned int size, const char *firstName,
|
|
|
|
const char *secondName) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// validate all entries
|
2020-06-23 19:05:42 +00:00
|
|
|
DoValidationEx(array, size, firstName, secondName);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int i = 0; i < size; ++i) {
|
|
|
|
int res = HasNameMatch(array[i]->mName, mScene->mRootNode);
|
|
|
|
if (0 == res) {
|
|
|
|
const std::string name = static_cast<char *>(array[i]->mName.data);
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportError("aiScene::%s[%i] has no corresponding node in the scene graph (%s)",
|
2020-06-23 19:05:42 +00:00
|
|
|
firstName, i, name.c_str());
|
|
|
|
} else if (1 != res) {
|
|
|
|
const std::string name = static_cast<char *>(array[i]->mName.data);
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportError("aiScene::%s[%i]: there are more than one nodes with %s as name",
|
2020-06-23 19:05:42 +00:00
|
|
|
firstName, i, name.c_str());
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Executes the post processing step on the given imported data.
|
2020-06-23 19:05:42 +00:00
|
|
|
void ValidateDSProcess::Execute(aiScene *pScene) {
|
2019-05-05 14:00:57 +00:00
|
|
|
mScene = pScene;
|
2018-04-26 12:10:18 +00:00
|
|
|
ASSIMP_LOG_DEBUG("ValidateDataStructureProcess begin");
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// validate the node graph of the scene
|
|
|
|
Validate(pScene->mRootNode);
|
|
|
|
|
|
|
|
// validate all meshes
|
|
|
|
if (pScene->mNumMeshes) {
|
2020-06-23 19:05:42 +00:00
|
|
|
DoValidation(pScene->mMeshes, pScene->mNumMeshes, "mMeshes", "mNumMeshes");
|
|
|
|
} else if (!(mScene->mFlags & AI_SCENE_FLAGS_INCOMPLETE)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportError("aiScene::mNumMeshes is 0. At least one mesh must be there");
|
2020-06-23 19:05:42 +00:00
|
|
|
} else if (pScene->mMeshes) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportError("aiScene::mMeshes is non-null although there are no meshes");
|
|
|
|
}
|
|
|
|
|
|
|
|
// validate all animations
|
|
|
|
if (pScene->mNumAnimations) {
|
2020-06-23 19:05:42 +00:00
|
|
|
DoValidation(pScene->mAnimations, pScene->mNumAnimations,
|
|
|
|
"mAnimations", "mNumAnimations");
|
|
|
|
} else if (pScene->mAnimations) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportError("aiScene::mAnimations is non-null although there are no animations");
|
|
|
|
}
|
|
|
|
|
|
|
|
// validate all cameras
|
|
|
|
if (pScene->mNumCameras) {
|
2020-06-23 19:05:42 +00:00
|
|
|
DoValidationWithNameCheck(pScene->mCameras, pScene->mNumCameras,
|
|
|
|
"mCameras", "mNumCameras");
|
|
|
|
} else if (pScene->mCameras) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportError("aiScene::mCameras is non-null although there are no cameras");
|
|
|
|
}
|
|
|
|
|
|
|
|
// validate all lights
|
|
|
|
if (pScene->mNumLights) {
|
2020-06-23 19:05:42 +00:00
|
|
|
DoValidationWithNameCheck(pScene->mLights, pScene->mNumLights,
|
|
|
|
"mLights", "mNumLights");
|
|
|
|
} else if (pScene->mLights) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportError("aiScene::mLights is non-null although there are no lights");
|
|
|
|
}
|
|
|
|
|
|
|
|
// validate all textures
|
|
|
|
if (pScene->mNumTextures) {
|
2020-06-23 19:05:42 +00:00
|
|
|
DoValidation(pScene->mTextures, pScene->mNumTextures,
|
|
|
|
"mTextures", "mNumTextures");
|
|
|
|
} else if (pScene->mTextures) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportError("aiScene::mTextures is non-null although there are no textures");
|
|
|
|
}
|
|
|
|
|
|
|
|
// validate all materials
|
|
|
|
if (pScene->mNumMaterials) {
|
2020-06-23 19:05:42 +00:00
|
|
|
DoValidation(pScene->mMaterials, pScene->mNumMaterials, "mMaterials", "mNumMaterials");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
else if (pScene->mMaterials) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportError("aiScene::mMaterials is non-null although there are no materials");
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
// if (!has)ReportError("The aiScene data structure is empty");
|
2018-04-26 12:10:18 +00:00
|
|
|
ASSIMP_LOG_DEBUG("ValidateDataStructureProcess end");
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-06-23 19:05:42 +00:00
|
|
|
void ValidateDSProcess::Validate(const aiLight *pLight) {
|
2015-05-19 03:57:13 +00:00
|
|
|
if (pLight->mType == aiLightSource_UNDEFINED)
|
|
|
|
ReportWarning("aiLight::mType is aiLightSource_UNDEFINED");
|
|
|
|
|
|
|
|
if (!pLight->mAttenuationConstant &&
|
2020-06-23 19:05:42 +00:00
|
|
|
!pLight->mAttenuationLinear &&
|
|
|
|
!pLight->mAttenuationQuadratic) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportWarning("aiLight::mAttenuationXXX - all are zero");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pLight->mAngleInnerCone > pLight->mAngleOuterCone)
|
|
|
|
ReportError("aiLight::mAngleInnerCone is larger than aiLight::mAngleOuterCone");
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
if (pLight->mColorDiffuse.IsBlack() && pLight->mColorAmbient.IsBlack() && pLight->mColorSpecular.IsBlack()) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportWarning("aiLight::mColorXXX - all are black and won't have any influence");
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
2015-05-19 03:52:10 +00:00
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-06-23 19:05:42 +00:00
|
|
|
void ValidateDSProcess::Validate(const aiCamera *pCamera) {
|
2015-05-19 03:57:13 +00:00
|
|
|
if (pCamera->mClipPlaneFar <= pCamera->mClipPlaneNear)
|
|
|
|
ReportError("aiCamera::mClipPlaneFar must be >= aiCamera::mClipPlaneNear");
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2023-05-03 22:00:52 +00:00
|
|
|
// There are many 3ds files with invalid FOVs. No reason to reject them at all ... a warning is appropriate.
|
2015-05-19 03:57:13 +00:00
|
|
|
if (!pCamera->mHorizontalFOV || pCamera->mHorizontalFOV >= (float)AI_MATH_PI)
|
2020-06-23 19:05:42 +00:00
|
|
|
ReportWarning("%f is not a valid value for aiCamera::mHorizontalFOV", pCamera->mHorizontalFOV);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-06-23 19:05:42 +00:00
|
|
|
void ValidateDSProcess::Validate(const aiMesh *pMesh) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// validate the material index of the mesh
|
2020-06-23 19:05:42 +00:00
|
|
|
if (mScene->mNumMaterials && pMesh->mMaterialIndex >= mScene->mNumMaterials) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportError("aiMesh::mMaterialIndex is invalid (value: %i maximum: %i)",
|
2020-06-23 19:05:42 +00:00
|
|
|
pMesh->mMaterialIndex, mScene->mNumMaterials - 1);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Validate(&pMesh->mName);
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int i = 0; i < pMesh->mNumFaces; ++i) {
|
|
|
|
aiFace &face = pMesh->mFaces[i];
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
if (pMesh->mPrimitiveTypes) {
|
|
|
|
switch (face.mNumIndices) {
|
2015-05-19 03:57:13 +00:00
|
|
|
case 0:
|
2020-06-23 19:05:42 +00:00
|
|
|
ReportError("aiMesh::mFaces[%i].mNumIndices is 0", i);
|
2015-05-19 03:57:13 +00:00
|
|
|
case 1:
|
2020-06-23 19:05:42 +00:00
|
|
|
if (0 == (pMesh->mPrimitiveTypes & aiPrimitiveType_POINT)) {
|
2017-11-17 23:34:00 +00:00
|
|
|
ReportError("aiMesh::mFaces[%i] is a POINT but aiMesh::mPrimitiveTypes "
|
2020-06-23 19:05:42 +00:00
|
|
|
"does not report the POINT flag",
|
|
|
|
i);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
2020-06-23 19:05:42 +00:00
|
|
|
if (0 == (pMesh->mPrimitiveTypes & aiPrimitiveType_LINE)) {
|
2017-11-17 23:34:00 +00:00
|
|
|
ReportError("aiMesh::mFaces[%i] is a LINE but aiMesh::mPrimitiveTypes "
|
2020-06-23 19:05:42 +00:00
|
|
|
"does not report the LINE flag",
|
|
|
|
i);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
2020-06-23 19:05:42 +00:00
|
|
|
if (0 == (pMesh->mPrimitiveTypes & aiPrimitiveType_TRIANGLE)) {
|
2017-11-17 23:34:00 +00:00
|
|
|
ReportError("aiMesh::mFaces[%i] is a TRIANGLE but aiMesh::mPrimitiveTypes "
|
2020-06-23 19:05:42 +00:00
|
|
|
"does not report the TRIANGLE flag",
|
|
|
|
i);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2020-06-23 19:05:42 +00:00
|
|
|
if (0 == (pMesh->mPrimitiveTypes & aiPrimitiveType_POLYGON)) {
|
2017-11-17 23:34:00 +00:00
|
|
|
this->ReportError("aiMesh::mFaces[%i] is a POLYGON but aiMesh::mPrimitiveTypes "
|
2020-06-23 19:05:42 +00:00
|
|
|
"does not report the POLYGON flag",
|
|
|
|
i);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!face.mIndices)
|
2020-06-23 19:05:42 +00:00
|
|
|
ReportError("aiMesh::mFaces[%i].mIndices is nullptr", i);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// positions must always be there ...
|
|
|
|
if (!pMesh->mNumVertices || (!pMesh->mVertices && !mScene->mFlags)) {
|
2018-05-19 20:02:54 +00:00
|
|
|
ReportError("The mesh %s contains no vertices", pMesh->mName.C_Str());
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pMesh->mNumVertices > AI_MAX_VERTICES) {
|
2020-06-23 19:05:42 +00:00
|
|
|
ReportError("Mesh has too many vertices: %u, but the limit is %u", pMesh->mNumVertices, AI_MAX_VERTICES);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
if (pMesh->mNumFaces > AI_MAX_FACES) {
|
2020-06-23 19:05:42 +00:00
|
|
|
ReportError("Mesh has too many faces: %u, but the limit is %u", pMesh->mNumFaces, AI_MAX_FACES);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// if tangents are there there must also be bitangent vectors ...
|
2020-06-23 19:05:42 +00:00
|
|
|
if ((pMesh->mTangents != nullptr) != (pMesh->mBitangents != nullptr)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportError("If there are tangents, bitangent vectors must be present as well");
|
|
|
|
}
|
|
|
|
|
|
|
|
// faces, too
|
2020-06-23 19:05:42 +00:00
|
|
|
if (!pMesh->mNumFaces || (!pMesh->mFaces && !mScene->mFlags)) {
|
2018-05-19 20:02:54 +00:00
|
|
|
ReportError("Mesh %s contains no faces", pMesh->mName.C_Str());
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// now check whether the face indexing layout is correct:
|
|
|
|
// unique vertices, pseudo-indexed.
|
|
|
|
std::vector<bool> abRefList;
|
2020-06-23 19:05:42 +00:00
|
|
|
abRefList.resize(pMesh->mNumVertices, false);
|
|
|
|
for (unsigned int i = 0; i < pMesh->mNumFaces; ++i) {
|
|
|
|
aiFace &face = pMesh->mFaces[i];
|
2015-05-19 03:57:13 +00:00
|
|
|
if (face.mNumIndices > AI_MAX_FACE_INDICES) {
|
2020-06-23 19:05:42 +00:00
|
|
|
ReportError("Face %u has too many faces: %u, but the limit is %u", i, face.mNumIndices, AI_MAX_FACE_INDICES);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int a = 0; a < face.mNumIndices; ++a) {
|
|
|
|
if (face.mIndices[a] >= pMesh->mNumVertices) {
|
|
|
|
ReportError("aiMesh::mFaces[%i]::mIndices[%i] is out of range", i, a);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
abRefList[face.mIndices[a]] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check whether there are vertices that aren't referenced by a face
|
|
|
|
bool b = false;
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int i = 0; i < pMesh->mNumVertices; ++i) {
|
|
|
|
if (!abRefList[i]) b = true;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
abRefList.clear();
|
2019-03-09 17:36:21 +00:00
|
|
|
if (b) {
|
2020-06-23 19:05:42 +00:00
|
|
|
ReportWarning("There are unreferenced vertices");
|
2019-03-09 17:36:21 +00:00
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// texture channel 2 may not be set if channel 1 is zero ...
|
|
|
|
{
|
|
|
|
unsigned int i = 0;
|
2020-06-23 19:05:42 +00:00
|
|
|
for (; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) {
|
|
|
|
if (!pMesh->HasTextureCoords(i)) break;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
for (; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i)
|
|
|
|
if (pMesh->HasTextureCoords(i)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportError("Texture coordinate channel %i exists "
|
2020-06-23 19:05:42 +00:00
|
|
|
"although the previous channel was nullptr.",
|
|
|
|
i);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// the same for the vertex colors
|
|
|
|
{
|
|
|
|
unsigned int i = 0;
|
2020-06-23 19:05:42 +00:00
|
|
|
for (; i < AI_MAX_NUMBER_OF_COLOR_SETS; ++i) {
|
|
|
|
if (!pMesh->HasVertexColors(i)) break;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
for (; i < AI_MAX_NUMBER_OF_COLOR_SETS; ++i)
|
|
|
|
if (pMesh->HasVertexColors(i)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportError("Vertex color channel %i is exists "
|
2020-06-23 19:05:42 +00:00
|
|
|
"although the previous channel was nullptr.",
|
|
|
|
i);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// now validate all bones
|
2020-06-23 19:05:42 +00:00
|
|
|
if (pMesh->mNumBones) {
|
|
|
|
if (!pMesh->mBones) {
|
|
|
|
ReportError("aiMesh::mBones is nullptr (aiMesh::mNumBones is %i)",
|
|
|
|
pMesh->mNumBones);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2016-04-05 21:23:53 +00:00
|
|
|
std::unique_ptr<float[]> afSum(nullptr);
|
2020-06-23 19:05:42 +00:00
|
|
|
if (pMesh->mNumVertices) {
|
2015-05-19 03:57:13 +00:00
|
|
|
afSum.reset(new float[pMesh->mNumVertices]);
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int i = 0; i < pMesh->mNumVertices; ++i)
|
2015-05-19 03:57:13 +00:00
|
|
|
afSum[i] = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check whether there are duplicate bone names
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int i = 0; i < pMesh->mNumBones; ++i) {
|
|
|
|
const aiBone *bone = pMesh->mBones[i];
|
2015-05-19 03:57:13 +00:00
|
|
|
if (bone->mNumWeights > AI_MAX_BONE_WEIGHTS) {
|
2020-06-23 19:05:42 +00:00
|
|
|
ReportError("Bone %u has too many weights: %u, but the limit is %u", i, bone->mNumWeights, AI_MAX_BONE_WEIGHTS);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
if (!pMesh->mBones[i]) {
|
|
|
|
ReportError("aiMesh::mBones[%i] is nullptr (aiMesh::mNumBones is %i)",
|
|
|
|
i, pMesh->mNumBones);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
Validate(pMesh, pMesh->mBones[i], afSum.get());
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int a = i + 1; a < pMesh->mNumBones; ++a) {
|
|
|
|
if (pMesh->mBones[i]->mName == pMesh->mBones[a]->mName) {
|
2018-11-09 10:54:12 +00:00
|
|
|
const char *name = "unknown";
|
2020-06-23 19:05:42 +00:00
|
|
|
if (nullptr != pMesh->mBones[i]->mName.C_Str()) {
|
|
|
|
name = pMesh->mBones[i]->mName.C_Str();
|
2018-11-08 21:12:05 +00:00
|
|
|
}
|
|
|
|
ReportError("aiMesh::mBones[%i], name = \"%s\" has the same name as "
|
2020-06-23 19:05:42 +00:00
|
|
|
"aiMesh::mBones[%i]",
|
|
|
|
i, name, a);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// check whether all bone weights for a vertex sum to 1.0 ...
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int i = 0; i < pMesh->mNumVertices; ++i) {
|
2015-05-19 03:57:13 +00:00
|
|
|
if (afSum[i] && (afSum[i] <= 0.94 || afSum[i] >= 1.05)) {
|
2020-06-23 19:05:42 +00:00
|
|
|
ReportWarning("aiMesh::mVertices[%i]: bone weight sum != 1.0 (sum is %f)", i, afSum[i]);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
} else if (pMesh->mBones) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportError("aiMesh::mBones is non-null although there are no bones");
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-06-23 19:05:42 +00:00
|
|
|
void ValidateDSProcess::Validate(const aiMesh *pMesh, const aiBone *pBone, float *afSum) {
|
2015-05-19 03:57:13 +00:00
|
|
|
this->Validate(&pBone->mName);
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
if (!pBone->mNumWeights) {
|
2023-05-03 22:00:52 +00:00
|
|
|
ReportWarning("aiBone::mNumWeights is zero");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// check whether all vertices affected by this bone are valid
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int i = 0; i < pBone->mNumWeights; ++i) {
|
|
|
|
if (pBone->mWeights[i].mVertexId >= pMesh->mNumVertices) {
|
|
|
|
ReportError("aiBone::mWeights[%i].mVertexId is out of range", i);
|
|
|
|
} else if (!pBone->mWeights[i].mWeight || pBone->mWeights[i].mWeight > 1.0f) {
|
|
|
|
ReportWarning("aiBone::mWeights[%i].mWeight has an invalid value", i);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
afSum[pBone->mWeights[i].mVertexId] += pBone->mWeights[i].mWeight;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-06-23 19:05:42 +00:00
|
|
|
void ValidateDSProcess::Validate(const aiAnimation *pAnimation) {
|
2015-05-19 03:57:13 +00:00
|
|
|
Validate(&pAnimation->mName);
|
|
|
|
|
2019-09-25 08:57:53 +00:00
|
|
|
// validate all animations
|
2020-06-23 19:05:42 +00:00
|
|
|
if (pAnimation->mNumChannels || pAnimation->mNumMorphMeshChannels) {
|
2019-09-25 08:57:53 +00:00
|
|
|
if (!pAnimation->mChannels && pAnimation->mNumChannels) {
|
2020-06-23 19:05:42 +00:00
|
|
|
ReportError("aiAnimation::mChannels is nullptr (aiAnimation::mNumChannels is %i)",
|
|
|
|
pAnimation->mNumChannels);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2019-09-25 08:57:53 +00:00
|
|
|
if (!pAnimation->mMorphMeshChannels && pAnimation->mNumMorphMeshChannels) {
|
2020-06-23 19:05:42 +00:00
|
|
|
ReportError("aiAnimation::mMorphMeshChannels is nullptr (aiAnimation::mNumMorphMeshChannels is %i)",
|
|
|
|
pAnimation->mNumMorphMeshChannels);
|
2019-09-25 08:57:53 +00:00
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int i = 0; i < pAnimation->mNumChannels; ++i) {
|
|
|
|
if (!pAnimation->mChannels[i]) {
|
|
|
|
ReportError("aiAnimation::mChannels[%i] is nullptr (aiAnimation::mNumChannels is %i)",
|
|
|
|
i, pAnimation->mNumChannels);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
Validate(pAnimation, pAnimation->mChannels[i]);
|
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int i = 0; i < pAnimation->mNumMorphMeshChannels; ++i) {
|
|
|
|
if (!pAnimation->mMorphMeshChannels[i]) {
|
|
|
|
ReportError("aiAnimation::mMorphMeshChannels[%i] is nullptr (aiAnimation::mNumMorphMeshChannels is %i)",
|
|
|
|
i, pAnimation->mNumMorphMeshChannels);
|
2019-09-25 08:57:53 +00:00
|
|
|
}
|
|
|
|
Validate(pAnimation, pAnimation->mMorphMeshChannels[i]);
|
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
} else {
|
|
|
|
ReportError("aiAnimation::mNumChannels is 0. At least one node animation channel must be there.");
|
2019-03-09 17:36:21 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-06-23 19:05:42 +00:00
|
|
|
void ValidateDSProcess::SearchForInvalidTextures(const aiMaterial *pMaterial,
|
|
|
|
aiTextureType type) {
|
2022-05-01 11:27:42 +00:00
|
|
|
const char *szType = aiTextureTypeToString(type);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// ****************************************************************************
|
|
|
|
// Search all keys of the material ...
|
|
|
|
// textures must be specified with ascending indices
|
|
|
|
// (e.g. diffuse #2 may not be specified if diffuse #1 is not there ...)
|
|
|
|
// ****************************************************************************
|
|
|
|
|
|
|
|
int iNumIndices = 0;
|
|
|
|
int iIndex = -1;
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int i = 0; i < pMaterial->mNumProperties; ++i) {
|
|
|
|
aiMaterialProperty *prop = pMaterial->mProperties[i];
|
2019-03-13 15:58:18 +00:00
|
|
|
ai_assert(nullptr != prop);
|
2020-06-23 19:05:42 +00:00
|
|
|
if (!::strcmp(prop->mKey.data, "$tex.file") && prop->mSemantic == static_cast<unsigned int>(type)) {
|
|
|
|
iIndex = std::max(iIndex, (int)prop->mIndex);
|
2015-05-19 03:57:13 +00:00
|
|
|
++iNumIndices;
|
|
|
|
|
2019-03-13 15:58:18 +00:00
|
|
|
if (aiPTI_String != prop->mType) {
|
|
|
|
ReportError("Material property %s is expected to be a string", prop->mKey.data);
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
if (iIndex + 1 != iNumIndices) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportError("%s #%i is set, but there are only %i %s textures",
|
2020-06-23 19:05:42 +00:00
|
|
|
szType, iIndex, iNumIndices, szType);
|
|
|
|
}
|
|
|
|
if (!iNumIndices) {
|
|
|
|
return;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
std::vector<aiTextureMapping> mappings(iNumIndices);
|
|
|
|
|
|
|
|
// Now check whether all UV indices are valid ...
|
|
|
|
bool bNoSpecified = true;
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int i = 0; i < pMaterial->mNumProperties; ++i) {
|
|
|
|
aiMaterialProperty *prop = pMaterial->mProperties[i];
|
|
|
|
if (static_cast<aiTextureType>(prop->mSemantic) != type) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((int)prop->mIndex >= iNumIndices) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportError("Found texture property with index %i, although there "
|
2020-06-23 19:05:42 +00:00
|
|
|
"are only %i textures of type %s",
|
|
|
|
prop->mIndex, iNumIndices, szType);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
if (!::strcmp(prop->mKey.data, "$tex.mapping")) {
|
|
|
|
if (aiPTI_Integer != prop->mType || prop->mDataLength < sizeof(aiTextureMapping)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportError("Material property %s%i is expected to be an integer (size is %i)",
|
2020-06-23 19:05:42 +00:00
|
|
|
prop->mKey.data, prop->mIndex, prop->mDataLength);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
mappings[prop->mIndex] = *((aiTextureMapping *)prop->mData);
|
|
|
|
} else if (!::strcmp(prop->mKey.data, "$tex.uvtrafo")) {
|
|
|
|
if (aiPTI_Float != prop->mType || prop->mDataLength < sizeof(aiUVTransform)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportError("Material property %s%i is expected to be 5 floats large (size is %i)",
|
2020-06-23 19:05:42 +00:00
|
|
|
prop->mKey.data, prop->mIndex, prop->mDataLength);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
//mappings[prop->mIndex] = ((aiUVTransform*)prop->mData);
|
|
|
|
} else if (!::strcmp(prop->mKey.data, "$tex.uvwsrc")) {
|
|
|
|
if (aiPTI_Integer != prop->mType || sizeof(int) > prop->mDataLength) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportError("Material property %s%i is expected to be an integer (size is %i)",
|
2020-06-23 19:05:42 +00:00
|
|
|
prop->mKey.data, prop->mIndex, prop->mDataLength);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
bNoSpecified = false;
|
|
|
|
|
|
|
|
// Ignore UV indices for texture channels that are not there ...
|
|
|
|
|
|
|
|
// Get the value
|
2020-06-23 19:05:42 +00:00
|
|
|
iIndex = *((unsigned int *)prop->mData);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// Check whether there is a mesh using this material
|
|
|
|
// which has not enough UV channels ...
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int a = 0; a < mScene->mNumMeshes; ++a) {
|
|
|
|
aiMesh *mesh = this->mScene->mMeshes[a];
|
|
|
|
if (mesh->mMaterialIndex == (unsigned int)i) {
|
2015-05-19 03:57:13 +00:00
|
|
|
int iChannels = 0;
|
2020-06-23 19:05:42 +00:00
|
|
|
while (mesh->HasTextureCoords(iChannels))
|
|
|
|
++iChannels;
|
|
|
|
if (iIndex >= iChannels) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportWarning("Invalid UV index: %i (key %s). Mesh %i has only %i UV channels",
|
2020-06-23 19:05:42 +00:00
|
|
|
iIndex, prop->mKey.data, a, iChannels);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
if (bNoSpecified) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// Assume that all textures are using the first UV channel
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int a = 0; a < mScene->mNumMeshes; ++a) {
|
|
|
|
aiMesh *mesh = mScene->mMeshes[a];
|
|
|
|
if (mesh->mMaterialIndex == (unsigned int)iIndex && mappings[0] == aiTextureMapping_UV) {
|
|
|
|
if (!mesh->mTextureCoords[0]) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// This is a special case ... it could be that the
|
|
|
|
// original mesh format intended the use of a special
|
|
|
|
// mapping here.
|
|
|
|
ReportWarning("UV-mapped texture, but there are no UV coords");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-06-23 19:05:42 +00:00
|
|
|
void ValidateDSProcess::Validate(const aiMaterial *pMaterial) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// check whether there are material keys that are obviously not legal
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int i = 0; i < pMaterial->mNumProperties; ++i) {
|
|
|
|
const aiMaterialProperty *prop = pMaterial->mProperties[i];
|
|
|
|
if (!prop) {
|
|
|
|
ReportError("aiMaterial::mProperties[%i] is nullptr (aiMaterial::mNumProperties is %i)",
|
|
|
|
i, pMaterial->mNumProperties);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
if (!prop->mDataLength || !prop->mData) {
|
|
|
|
ReportError("aiMaterial::mProperties[%i].mDataLength or "
|
2020-06-23 19:05:42 +00:00
|
|
|
"aiMaterial::mProperties[%i].mData is 0",
|
|
|
|
i, i);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
// check all predefined types
|
2020-06-23 19:05:42 +00:00
|
|
|
if (aiPTI_String == prop->mType) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// FIX: strings are now stored in a less expensive way, but we can't use the
|
|
|
|
// validation routine for 'normal' aiStrings
|
2020-06-23 19:05:42 +00:00
|
|
|
if (prop->mDataLength < 5 || prop->mDataLength < 4 + (*reinterpret_cast<uint32_t *>(prop->mData)) + 1) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportError("aiMaterial::mProperties[%i].mDataLength is "
|
2020-06-23 19:05:42 +00:00
|
|
|
"too small to contain a string (%i, needed: %i)",
|
|
|
|
i, prop->mDataLength, static_cast<int>(sizeof(aiString)));
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
if (prop->mData[prop->mDataLength - 1]) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportError("Missing null-terminator in string material property");
|
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
// Validate((const aiString*)prop->mData);
|
|
|
|
} else if (aiPTI_Float == prop->mType) {
|
|
|
|
if (prop->mDataLength < sizeof(float)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportError("aiMaterial::mProperties[%i].mDataLength is "
|
2020-06-23 19:05:42 +00:00
|
|
|
"too small to contain a float (%i, needed: %i)",
|
|
|
|
i, prop->mDataLength, static_cast<int>(sizeof(float)));
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
} else if (aiPTI_Integer == prop->mType) {
|
|
|
|
if (prop->mDataLength < sizeof(int)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportError("aiMaterial::mProperties[%i].mDataLength is "
|
2020-06-23 19:05:42 +00:00
|
|
|
"too small to contain an integer (%i, needed: %i)",
|
|
|
|
i, prop->mDataLength, static_cast<int>(sizeof(int)));
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// TODO: check whether there is a key with an unknown name ...
|
|
|
|
}
|
|
|
|
|
|
|
|
// make some more specific tests
|
2016-07-16 23:49:28 +00:00
|
|
|
ai_real fTemp;
|
2015-05-19 03:57:13 +00:00
|
|
|
int iShading;
|
2020-06-23 19:05:42 +00:00
|
|
|
if (AI_SUCCESS == aiGetMaterialInteger(pMaterial, AI_MATKEY_SHADING_MODEL, &iShading)) {
|
|
|
|
switch ((aiShadingMode)iShading) {
|
2015-05-19 03:57:13 +00:00
|
|
|
case aiShadingMode_Blinn:
|
|
|
|
case aiShadingMode_CookTorrance:
|
|
|
|
case aiShadingMode_Phong:
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
if (AI_SUCCESS != aiGetMaterialFloat(pMaterial, AI_MATKEY_SHININESS, &fTemp)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportWarning("A specular shading model is specified but there is no "
|
2020-06-23 19:05:42 +00:00
|
|
|
"AI_MATKEY_SHININESS key");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
if (AI_SUCCESS == aiGetMaterialFloat(pMaterial, AI_MATKEY_SHININESS_STRENGTH, &fTemp) && !fTemp) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportWarning("A specular shading model is specified but the value of the "
|
2020-06-23 19:05:42 +00:00
|
|
|
"AI_MATKEY_SHININESS_STRENGTH key is 0.0");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
break;
|
2019-05-05 11:39:10 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
if (AI_SUCCESS == aiGetMaterialFloat(pMaterial, AI_MATKEY_OPACITY, &fTemp) && (!fTemp || fTemp > 1.01)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportWarning("Invalid opacity value (must be 0 < opacity < 1.0)");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check whether there are invalid texture keys
|
|
|
|
// TODO: that's a relict of the past, where texture type and index were baked
|
|
|
|
// into the material string ... we could do that in one single pass.
|
2020-06-23 19:05:42 +00:00
|
|
|
SearchForInvalidTextures(pMaterial, aiTextureType_DIFFUSE);
|
|
|
|
SearchForInvalidTextures(pMaterial, aiTextureType_SPECULAR);
|
|
|
|
SearchForInvalidTextures(pMaterial, aiTextureType_AMBIENT);
|
|
|
|
SearchForInvalidTextures(pMaterial, aiTextureType_EMISSIVE);
|
|
|
|
SearchForInvalidTextures(pMaterial, aiTextureType_OPACITY);
|
|
|
|
SearchForInvalidTextures(pMaterial, aiTextureType_SHININESS);
|
|
|
|
SearchForInvalidTextures(pMaterial, aiTextureType_HEIGHT);
|
|
|
|
SearchForInvalidTextures(pMaterial, aiTextureType_NORMALS);
|
|
|
|
SearchForInvalidTextures(pMaterial, aiTextureType_DISPLACEMENT);
|
|
|
|
SearchForInvalidTextures(pMaterial, aiTextureType_LIGHTMAP);
|
|
|
|
SearchForInvalidTextures(pMaterial, aiTextureType_REFLECTION);
|
|
|
|
SearchForInvalidTextures(pMaterial, aiTextureType_BASE_COLOR);
|
|
|
|
SearchForInvalidTextures(pMaterial, aiTextureType_NORMAL_CAMERA);
|
|
|
|
SearchForInvalidTextures(pMaterial, aiTextureType_EMISSION_COLOR);
|
|
|
|
SearchForInvalidTextures(pMaterial, aiTextureType_METALNESS);
|
|
|
|
SearchForInvalidTextures(pMaterial, aiTextureType_DIFFUSE_ROUGHNESS);
|
|
|
|
SearchForInvalidTextures(pMaterial, aiTextureType_AMBIENT_OCCLUSION);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-06-23 19:05:42 +00:00
|
|
|
void ValidateDSProcess::Validate(const aiTexture *pTexture) {
|
|
|
|
// the data section may NEVER be nullptr
|
|
|
|
if (nullptr == pTexture->pcData) {
|
|
|
|
ReportError("aiTexture::pcData is nullptr");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
if (pTexture->mHeight) {
|
|
|
|
if (!pTexture->mWidth) {
|
|
|
|
ReportError("aiTexture::mWidth is zero (aiTexture::mHeight is %i, uncompressed texture)",
|
|
|
|
pTexture->mHeight);
|
2019-03-09 17:36:21 +00:00
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
} else {
|
2015-05-19 03:57:13 +00:00
|
|
|
if (!pTexture->mWidth) {
|
|
|
|
ReportError("aiTexture::mWidth is zero (compressed texture)");
|
|
|
|
}
|
2020-01-23 20:26:49 +00:00
|
|
|
if ('\0' != pTexture->achFormatHint[HINTMAXTEXTURELEN - 1]) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportWarning("aiTexture::achFormatHint must be zero-terminated");
|
2020-06-23 19:05:42 +00:00
|
|
|
} else if ('.' == pTexture->achFormatHint[0]) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportWarning("aiTexture::achFormatHint should contain a file extension "
|
2020-06-23 19:05:42 +00:00
|
|
|
"without a leading dot (format hint: %s).",
|
|
|
|
pTexture->achFormatHint);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
const char *sz = pTexture->achFormatHint;
|
2015-05-19 03:57:13 +00:00
|
|
|
if ((sz[0] >= 'A' && sz[0] <= 'Z') ||
|
2020-06-23 19:05:42 +00:00
|
|
|
(sz[1] >= 'A' && sz[1] <= 'Z') ||
|
|
|
|
(sz[2] >= 'A' && sz[2] <= 'Z') ||
|
|
|
|
(sz[3] >= 'A' && sz[3] <= 'Z')) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportError("aiTexture::achFormatHint contains non-lowercase letters");
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-06-23 19:05:42 +00:00
|
|
|
void ValidateDSProcess::Validate(const aiAnimation *pAnimation,
|
|
|
|
const aiNodeAnim *pNodeAnim) {
|
2015-05-19 03:57:13 +00:00
|
|
|
Validate(&pNodeAnim->mNodeName);
|
|
|
|
|
2019-03-10 17:12:56 +00:00
|
|
|
if (!pNodeAnim->mNumPositionKeys && !pNodeAnim->mScalingKeys && !pNodeAnim->mNumRotationKeys) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportError("Empty node animation channel");
|
2019-03-10 17:12:56 +00:00
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
// otherwise check whether one of the keys exceeds the total duration of the animation
|
2020-06-23 19:05:42 +00:00
|
|
|
if (pNodeAnim->mNumPositionKeys) {
|
|
|
|
if (!pNodeAnim->mPositionKeys) {
|
|
|
|
ReportError("aiNodeAnim::mPositionKeys is nullptr (aiNodeAnim::mNumPositionKeys is %i)",
|
|
|
|
pNodeAnim->mNumPositionKeys);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
double dLast = -10e10;
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int i = 0; i < pNodeAnim->mNumPositionKeys; ++i) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// ScenePreprocessor will compute the duration if still the default value
|
|
|
|
// (Aramis) Add small epsilon, comparison tended to fail if max_time == duration,
|
|
|
|
// seems to be due the compilers register usage/width.
|
2020-06-23 19:05:42 +00:00
|
|
|
if (pAnimation->mDuration > 0. && pNodeAnim->mPositionKeys[i].mTime > pAnimation->mDuration + 0.001) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportError("aiNodeAnim::mPositionKeys[%i].mTime (%.5f) is larger "
|
2020-06-23 19:05:42 +00:00
|
|
|
"than aiAnimation::mDuration (which is %.5f)",
|
|
|
|
i,
|
|
|
|
(float)pNodeAnim->mPositionKeys[i].mTime,
|
|
|
|
(float)pAnimation->mDuration);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
if (i && pNodeAnim->mPositionKeys[i].mTime <= dLast) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportWarning("aiNodeAnim::mPositionKeys[%i].mTime (%.5f) is smaller "
|
2020-06-23 19:05:42 +00:00
|
|
|
"than aiAnimation::mPositionKeys[%i] (which is %.5f)",
|
|
|
|
i,
|
|
|
|
(float)pNodeAnim->mPositionKeys[i].mTime,
|
|
|
|
i - 1, (float)dLast);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
dLast = pNodeAnim->mPositionKeys[i].mTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// rotation keys
|
2020-06-23 19:05:42 +00:00
|
|
|
if (pNodeAnim->mNumRotationKeys) {
|
|
|
|
if (!pNodeAnim->mRotationKeys) {
|
|
|
|
ReportError("aiNodeAnim::mRotationKeys is nullptr (aiNodeAnim::mNumRotationKeys is %i)",
|
|
|
|
pNodeAnim->mNumRotationKeys);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
double dLast = -10e10;
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int i = 0; i < pNodeAnim->mNumRotationKeys; ++i) {
|
|
|
|
if (pAnimation->mDuration > 0. && pNodeAnim->mRotationKeys[i].mTime > pAnimation->mDuration + 0.001) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportError("aiNodeAnim::mRotationKeys[%i].mTime (%.5f) is larger "
|
2020-06-23 19:05:42 +00:00
|
|
|
"than aiAnimation::mDuration (which is %.5f)",
|
|
|
|
i,
|
|
|
|
(float)pNodeAnim->mRotationKeys[i].mTime,
|
|
|
|
(float)pAnimation->mDuration);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
if (i && pNodeAnim->mRotationKeys[i].mTime <= dLast) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportWarning("aiNodeAnim::mRotationKeys[%i].mTime (%.5f) is smaller "
|
2020-06-23 19:05:42 +00:00
|
|
|
"than aiAnimation::mRotationKeys[%i] (which is %.5f)",
|
|
|
|
i,
|
|
|
|
(float)pNodeAnim->mRotationKeys[i].mTime,
|
|
|
|
i - 1, (float)dLast);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
dLast = pNodeAnim->mRotationKeys[i].mTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// scaling keys
|
2020-06-23 19:05:42 +00:00
|
|
|
if (pNodeAnim->mNumScalingKeys) {
|
|
|
|
if (!pNodeAnim->mScalingKeys) {
|
|
|
|
ReportError("aiNodeAnim::mScalingKeys is nullptr (aiNodeAnim::mNumScalingKeys is %i)",
|
|
|
|
pNodeAnim->mNumScalingKeys);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
double dLast = -10e10;
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int i = 0; i < pNodeAnim->mNumScalingKeys; ++i) {
|
|
|
|
if (pAnimation->mDuration > 0. && pNodeAnim->mScalingKeys[i].mTime > pAnimation->mDuration + 0.001) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportError("aiNodeAnim::mScalingKeys[%i].mTime (%.5f) is larger "
|
2020-06-23 19:05:42 +00:00
|
|
|
"than aiAnimation::mDuration (which is %.5f)",
|
|
|
|
i,
|
|
|
|
(float)pNodeAnim->mScalingKeys[i].mTime,
|
|
|
|
(float)pAnimation->mDuration);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
if (i && pNodeAnim->mScalingKeys[i].mTime <= dLast) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportWarning("aiNodeAnim::mScalingKeys[%i].mTime (%.5f) is smaller "
|
2020-06-23 19:05:42 +00:00
|
|
|
"than aiAnimation::mScalingKeys[%i] (which is %.5f)",
|
|
|
|
i,
|
|
|
|
(float)pNodeAnim->mScalingKeys[i].mTime,
|
|
|
|
i - 1, (float)dLast);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
dLast = pNodeAnim->mScalingKeys[i].mTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pNodeAnim->mNumScalingKeys && !pNodeAnim->mNumRotationKeys &&
|
2020-06-23 19:05:42 +00:00
|
|
|
!pNodeAnim->mNumPositionKeys) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportError("A node animation channel must have at least one subtrack");
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
2020-06-23 19:05:42 +00:00
|
|
|
void ValidateDSProcess::Validate(const aiAnimation *pAnimation,
|
|
|
|
const aiMeshMorphAnim *pMeshMorphAnim) {
|
2019-09-25 08:57:53 +00:00
|
|
|
Validate(&pMeshMorphAnim->mName);
|
|
|
|
|
|
|
|
if (!pMeshMorphAnim->mNumKeys) {
|
2021-01-23 00:52:46 +00:00
|
|
|
ReportWarning("Empty mesh morph animation channel");
|
2021-01-23 00:56:35 +00:00
|
|
|
return;
|
2019-09-25 08:57:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// otherwise check whether one of the keys exceeds the total duration of the animation
|
2020-06-23 19:05:42 +00:00
|
|
|
if (pMeshMorphAnim->mNumKeys) {
|
|
|
|
if (!pMeshMorphAnim->mKeys) {
|
|
|
|
ReportError("aiMeshMorphAnim::mKeys is nullptr (aiMeshMorphAnim::mNumKeys is %i)",
|
|
|
|
pMeshMorphAnim->mNumKeys);
|
2019-09-25 08:57:53 +00:00
|
|
|
}
|
|
|
|
double dLast = -10e10;
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int i = 0; i < pMeshMorphAnim->mNumKeys; ++i) {
|
2019-09-25 08:57:53 +00:00
|
|
|
// ScenePreprocessor will compute the duration if still the default value
|
|
|
|
// (Aramis) Add small epsilon, comparison tended to fail if max_time == duration,
|
|
|
|
// seems to be due the compilers register usage/width.
|
2020-06-23 19:05:42 +00:00
|
|
|
if (pAnimation->mDuration > 0. && pMeshMorphAnim->mKeys[i].mTime > pAnimation->mDuration + 0.001) {
|
2019-09-25 08:57:53 +00:00
|
|
|
ReportError("aiMeshMorphAnim::mKeys[%i].mTime (%.5f) is larger "
|
2020-06-23 19:05:42 +00:00
|
|
|
"than aiAnimation::mDuration (which is %.5f)",
|
|
|
|
i,
|
|
|
|
(float)pMeshMorphAnim->mKeys[i].mTime,
|
|
|
|
(float)pAnimation->mDuration);
|
2019-09-25 08:57:53 +00:00
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
if (i && pMeshMorphAnim->mKeys[i].mTime <= dLast) {
|
2019-09-25 08:57:53 +00:00
|
|
|
ReportWarning("aiMeshMorphAnim::mKeys[%i].mTime (%.5f) is smaller "
|
2020-06-23 19:05:42 +00:00
|
|
|
"than aiMeshMorphAnim::mKeys[%i] (which is %.5f)",
|
|
|
|
i,
|
|
|
|
(float)pMeshMorphAnim->mKeys[i].mTime,
|
|
|
|
i - 1, (float)dLast);
|
2019-09-25 08:57:53 +00:00
|
|
|
}
|
|
|
|
dLast = pMeshMorphAnim->mKeys[i].mTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-06-23 19:05:42 +00:00
|
|
|
void ValidateDSProcess::Validate(const aiNode *pNode) {
|
2019-03-09 17:01:45 +00:00
|
|
|
if (!pNode) {
|
2020-06-23 19:05:42 +00:00
|
|
|
ReportError("A node of the scene-graph is nullptr");
|
2019-03-09 17:01:45 +00:00
|
|
|
}
|
|
|
|
// Validate node name string first so that it's safe to use in below expressions
|
2015-05-19 03:57:13 +00:00
|
|
|
this->Validate(&pNode->mName);
|
2020-06-23 19:05:42 +00:00
|
|
|
const char *nodeName = (&pNode->mName)->C_Str();
|
|
|
|
if (pNode != mScene->mRootNode && !pNode->mParent) {
|
|
|
|
ReportError("Non-root node %s lacks a valid parent (aiNode::mParent is nullptr) ", nodeName);
|
2019-03-09 17:01:45 +00:00
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// validate all meshes
|
2020-06-23 19:05:42 +00:00
|
|
|
if (pNode->mNumMeshes) {
|
|
|
|
if (!pNode->mMeshes) {
|
|
|
|
ReportError("aiNode::mMeshes is nullptr for node %s (aiNode::mNumMeshes is %i)",
|
|
|
|
nodeName, pNode->mNumMeshes);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
std::vector<bool> abHadMesh;
|
2020-06-23 19:05:42 +00:00
|
|
|
abHadMesh.resize(mScene->mNumMeshes, false);
|
|
|
|
for (unsigned int i = 0; i < pNode->mNumMeshes; ++i) {
|
|
|
|
if (pNode->mMeshes[i] >= mScene->mNumMeshes) {
|
2019-03-09 17:01:45 +00:00
|
|
|
ReportError("aiNode::mMeshes[%i] is out of range for node %s (maximum is %i)",
|
2020-06-23 19:05:42 +00:00
|
|
|
pNode->mMeshes[i], nodeName, mScene->mNumMeshes - 1);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
if (abHadMesh[pNode->mMeshes[i]]) {
|
2019-03-09 17:01:45 +00:00
|
|
|
ReportError("aiNode::mMeshes[%i] is already referenced by this node %s (value: %i)",
|
2020-06-23 19:05:42 +00:00
|
|
|
i, nodeName, pNode->mMeshes[i]);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
abHadMesh[pNode->mMeshes[i]] = true;
|
|
|
|
}
|
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
if (pNode->mNumChildren) {
|
|
|
|
if (!pNode->mChildren) {
|
|
|
|
ReportError("aiNode::mChildren is nullptr for node %s (aiNode::mNumChildren is %i)",
|
|
|
|
nodeName, pNode->mNumChildren);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
for (unsigned int i = 0; i < pNode->mNumChildren; ++i) {
|
2023-03-09 12:31:29 +00:00
|
|
|
const aiNode *pChild = pNode->mChildren[i];
|
|
|
|
Validate(pChild);
|
|
|
|
if (pChild->mParent != pNode) {
|
|
|
|
const char *parentName = (pChild->mParent != nullptr) ? pChild->mParent->mName.C_Str() : "null";
|
|
|
|
ReportError("aiNode \"%s\" child %i \"%s\" parent is someone else: \"%s\"", pNode->mName.C_Str(), i, pChild->mName.C_Str(), parentName);
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-06-23 19:05:42 +00:00
|
|
|
void ValidateDSProcess::Validate(const aiString *pString) {
|
|
|
|
if (pString->length > MAXLEN) {
|
2019-09-22 07:12:37 +00:00
|
|
|
ReportError("aiString::length is too large (%u, maximum is %lu)",
|
2020-06-23 19:05:42 +00:00
|
|
|
pString->length, MAXLEN);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-06-23 19:05:42 +00:00
|
|
|
const char *sz = pString->data;
|
|
|
|
while (true) {
|
|
|
|
if ('\0' == *sz) {
|
|
|
|
if (pString->length != (unsigned int)(sz - pString->data)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportError("aiString::data is invalid: the terminal zero is at a wrong offset");
|
2019-03-09 17:36:21 +00:00
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
break;
|
2020-06-23 19:05:42 +00:00
|
|
|
} else if (sz >= &pString->data[MAXLEN]) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ReportError("aiString::data is invalid. There is no terminal character");
|
2019-03-09 17:36:21 +00:00
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
++sz;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|