Merge branch 'master' into build_fixes

pull/3587/head
Kim Kulling 2021-01-21 09:03:06 +01:00 committed by GitHub
commit 7dcac538f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 67 additions and 44 deletions

View File

@ -61,12 +61,12 @@ namespace Assimp {
void AMFImporter::ParseNode_Mesh(XmlNode &node) {
AMFNodeElementBase *ne = nullptr;
// create new mesh object.
ne = new AMFMesh(mNodeElement_Cur);
// Check for child nodes
if (0 != ASSIMP_stricmp(node.name(), "mesh")) {
return;
}
// create new mesh object.
ne = new AMFMesh(mNodeElement_Cur);
bool found_verts = false, found_volumes = false;
if (!node.empty()) {
ParseHelper_Node_Enter(ne);

View File

@ -165,15 +165,15 @@ void AMFImporter::ParseNode_Texture(XmlNode &node) {
std::string type = node.attribute("type").as_string();
bool tiled = node.attribute("tiled").as_bool();
// create new texture object.
AMFNodeElementBase *ne = new AMFTexture(mNodeElement_Cur);
AMFTexture& als = *((AMFTexture*)ne);// alias for convenience
if (node.empty()) {
return;
}
// create new texture object.
AMFNodeElementBase *ne = new AMFTexture(mNodeElement_Cur);
AMFTexture& als = *((AMFTexture*)ne);// alias for convenience
std::string enc64_data = node.value();
// Check for child nodes

View File

@ -560,18 +560,17 @@ inline void BufferView::Read(Value &obj, Asset &r) {
buffer = r.buffers.Retrieve(bufferVal->GetUint());
}
if (!buffer) {
throw DeadlyImportError("GLTF: Buffer view without valid buffer.");
}
byteOffset = MemberOrDefault(obj, "byteOffset", size_t(0));
byteLength = MemberOrDefault(obj, "byteLength", size_t(0));
byteStride = MemberOrDefault(obj, "byteStride", 0u);
// Check length
if ((byteOffset + byteLength) > buffer->byteLength) {
const uint8_t val_size = 64;
char val[val_size];
ai_snprintf(val, val_size, "%llu, %llu", (unsigned long long)byteOffset, (unsigned long long)byteLength);
throw DeadlyImportError("GLTF: Buffer view with offset/length (", val, ") is out of range.");
throw DeadlyImportError("GLTF: Buffer view with offset/length (", byteOffset, "/", byteLength, ") is out of range.");
}
}
@ -649,13 +648,14 @@ inline void Accessor::Read(Value &obj, Asset &r) {
if (bufferView) {
// Check length
unsigned long long byteLength = (unsigned long long)GetBytesPerComponent() * (unsigned long long)count;
// handle integer overflow
if (byteLength < count) {
throw DeadlyImportError("GLTF: Accessor with offset/count (", byteOffset, "/", count, ") is out of range.");
}
if ((byteOffset + byteLength) > bufferView->byteLength || (bufferView->byteOffset + byteOffset + byteLength) > bufferView->buffer->byteLength) {
const uint8_t val_size = 64;
char val[val_size];
ai_snprintf(val, val_size, "%llu, %llu", (unsigned long long)byteOffset, (unsigned long long)byteLength);
throw DeadlyImportError("GLTF: Accessor with offset/length (", val, ") is out of range.");
throw DeadlyImportError("GLTF: Accessor with offset/length (", byteOffset, "/", byteLength, ") is out of range.");
}
}

View File

@ -60,19 +60,32 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using namespace Assimp;
#ifdef _WIN32
const std::wstring wdummy;
static std::wstring Utf8ToWide(const char *in) {
if (nullptr == in) {
return wdummy;
}
int size = MultiByteToWideChar(CP_UTF8, 0, in, -1, nullptr, 0);
// size includes terminating null; std::wstring adds null automatically
std::wstring out(static_cast<size_t>(size) - 1, L'\0');
MultiByteToWideChar(CP_UTF8, 0, in, -1, &out[0], size);
return out;
}
const std::string dummy;
static std::string WideToUtf8(const wchar_t *in) {
if (nullptr == in) {
return dummy;
}
int size = WideCharToMultiByte(CP_UTF8, 0, in, -1, nullptr, 0, nullptr, nullptr);
// size includes terminating null; std::string adds null automatically
std::string out(static_cast<size_t>(size) - 1, '\0');
WideCharToMultiByte(CP_UTF8, 0, in, -1, &out[0], size, nullptr, nullptr);
return out;
}
#endif
@ -104,7 +117,12 @@ IOStream *DefaultIOSystem::Open(const char *strFile, const char *strMode) {
ai_assert(strMode != nullptr);
FILE *file;
#ifdef _WIN32
file = ::_wfopen(Utf8ToWide(strFile).c_str(), Utf8ToWide(strMode).c_str());
std::wstring name = Utf8ToWide(strFile);
if (name.empty()) {
return nullptr;
}
file = ::_wfopen(name.c_str(), Utf8ToWide(strMode).c_str());
#else
file = ::fopen(strFile, strMode);
#endif

View File

@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2020, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
@ -52,8 +51,12 @@ void ScenePreprocessor::ProcessScene() {
ai_assert(scene != nullptr);
// Process all meshes
for (unsigned int i = 0; i < scene->mNumMeshes; ++i)
for (unsigned int i = 0; i < scene->mNumMeshes; ++i) {
if (nullptr == scene->mMeshes[i]) {
continue;
}
ProcessMesh(scene->mMeshes[i]);
}
// - nothing to do for nodes for the moment
// - nothing to do for textures for the moment
@ -61,8 +64,12 @@ void ScenePreprocessor::ProcessScene() {
// - nothing to do for cameras for the moment
// Process all animations
for (unsigned int i = 0; i < scene->mNumAnimations; ++i)
for (unsigned int i = 0; i < scene->mNumAnimations; ++i) {
if (nullptr == scene->mAnimations[i]) {
continue;
}
ProcessAnimation(scene->mAnimations[i]);
}
// Generate a default material if none was specified
if (!scene->mNumMaterials && scene->mNumMeshes) {

View File

@ -152,7 +152,7 @@ zlib_filefunc_def IOSystem2Unzip::get(IOSystem *pIOHandler) {
mapping.ztell_file = (tell_file_func)tell;
mapping.zseek_file = (seek_file_func)seek;
mapping.zclose_file = (close_file_func)close;
mapping.zerror_file = (error_file_func)testerror;
mapping.zerror_file = testerror;
mapping.opaque = reinterpret_cast<voidpf>(pIOHandler);

View File

@ -198,11 +198,9 @@ endif(MINGW)
add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
IF(WIN32)
INSTALL( TARGETS zlibstatic
EXPORT "${TARGETS_EXPORT_NAME}"
LIBRARY DESTINATION ${ASSIMP_LIB_INSTALL_DIR}
ARCHIVE DESTINATION ${ASSIMP_LIB_INSTALL_DIR}
RUNTIME DESTINATION ${ASSIMP_BIN_INSTALL_DIR}
COMPONENT ${LIBASSIMP_COMPONENT})
ENDIF()
INSTALL( TARGETS zlibstatic
EXPORT "${TARGETS_EXPORT_NAME}"
LIBRARY DESTINATION ${ASSIMP_LIB_INSTALL_DIR}
ARCHIVE DESTINATION ${ASSIMP_LIB_INSTALL_DIR}
RUNTIME DESTINATION ${ASSIMP_BIN_INSTALL_DIR}
COMPONENT ${LIBASSIMP_COMPONENT})

View File

@ -145,11 +145,7 @@ int ASSIMP_stricmp(const char *s1, const char *s2) {
#if (defined _MSC_VER)
return ::_stricmp(s1, s2);
#elif defined(__GNUC__)
return ::strcasecmp(s1, s2);
#else
char c1, c2;
do {
c1 = tolower(*s1++);

View File

@ -735,9 +735,9 @@ public:
* #GetTextureCount() can be used to determine the number of textures
* per texture type.
* @param path Receives the path to the texture.
* If the texture is embedded, receives a '*' followed by the id of
* the texture (for the textures stored in the corresponding scene) which
* can be converted to an int using a function like atoi.
* Use aiScene::GetEmbeddedTexture() method to determine if returned path
* is an image file to be opened or a string key of embedded texture stored in the corresponding scene
* (could be a '*' followed by the id of the texture in case of no name)
* NULL is a valid value.
* @param mapping The texture mapping.
* NULL is allowed as value.

View File

@ -305,9 +305,9 @@ struct aiString {
/** Copy a const char* to the aiString */
void Set(const char *sz) {
const ai_int32 len = (ai_uint32)::strlen(sz);
ai_int32 len = (ai_uint32)::strlen(sz);
if (len > (ai_int32)MAXLEN - 1) {
return;
len = (ai_int32) MAXLEN - 1;
}
length = len;
memcpy(data, sz, len);
@ -321,7 +321,10 @@ struct aiString {
}
length = rOther.length;
;
if (length >(MAXLEN - 1)) {
length = (ai_int32) MAXLEN - 1;
}
memcpy(data, rOther.data, length);
data[length] = '\0';
return *this;

View File

@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2020, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
@ -154,6 +152,9 @@ const aiVector3t<TReal>& aiVector3t<TReal>::operator *= (TReal f) {
template <typename TReal>
AI_FORCE_INLINE
const aiVector3t<TReal>& aiVector3t<TReal>::operator /= (TReal f) {
if ( f == static_cast<TReal>(0.0)) {
return *this;
}
const TReal invF = (TReal) 1.0 / f;
x *= invF;
y *= invF;