Переглянути джерело

Merge pull request #2948 from malortie/update-texture-format-size

Updated places where read/write for achFormatHint (Redone).
Kim Kulling 5 роки тому
батько
коміт
dbee3807b3

+ 2 - 1
code/Assbin/AssbinExporter.cpp

@@ -413,7 +413,8 @@ protected:
 
         Write<unsigned int>(&chunk,tex->mWidth);
         Write<unsigned int>(&chunk,tex->mHeight);
-        chunk.Write( tex->achFormatHint, sizeof(char), 4 );
+        // Write the texture format, but don't include the null terminator.
+        chunk.Write( tex->achFormatHint, sizeof(char), HINTMAXTEXTURELEN - 1 );
 
         if(!shortened) {
             if (!tex->mHeight) {

+ 1 - 1
code/Assbin/AssbinLoader.cpp

@@ -535,7 +535,7 @@ void AssbinImporter::ReadBinaryTexture(IOStream * stream, aiTexture* tex) {
 
     tex->mWidth = Read<unsigned int>(stream);
     tex->mHeight = Read<unsigned int>(stream);
-    stream->Read( tex->achFormatHint, sizeof(char), 4 );
+    stream->Read( tex->achFormatHint, sizeof(char), HINTMAXTEXTURELEN - 1 );
 
     if(!shortened) {
         if (!tex->mHeight) {

+ 1 - 1
code/PostProcessing/ValidateDataStructure.cpp

@@ -798,7 +798,7 @@ void ValidateDSProcess::Validate( const aiTexture* pTexture)
         if (!pTexture->mWidth) {
             ReportError("aiTexture::mWidth is zero (compressed texture)");
         }
-        if ('\0' != pTexture->achFormatHint[3]) {
+        if ('\0' != pTexture->achFormatHint[HINTMAXTEXTURELEN - 1]) {
             ReportWarning("aiTexture::achFormatHint must be zero-terminated");
         }
         else if ('.'  == pTexture->achFormatHint[0])    {

+ 1 - 2
include/assimp/texture.h

@@ -207,8 +207,7 @@ struct aiTexture {
     , mHeight(0)
     , pcData(nullptr)
     , mFilename() {
-        achFormatHint[0] = achFormatHint[1] = 0;
-        achFormatHint[2] = achFormatHint[3] = 0;
+        memset(achFormatHint, 0, sizeof(achFormatHint));
     }
 
     // Destruction

+ 4 - 0
tools/assimp_cmd/CompareDump.cpp

@@ -800,6 +800,10 @@ void CompareOnTheFlyTexture(comparer_context& comp) {
     comp.cmp<char>("achFormatHint[1]");
     comp.cmp<char>("achFormatHint[2]");
     comp.cmp<char>("achFormatHint[3]");
+    comp.cmp<char>("achFormatHint[4]");
+    comp.cmp<char>("achFormatHint[5]");
+    comp.cmp<char>("achFormatHint[6]");
+    comp.cmp<char>("achFormatHint[7]");
 }
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////

+ 2 - 1
tools/assimp_cmd/WriteDumb.cpp

@@ -312,7 +312,8 @@ uint32_t WriteBinaryTexture(const aiTexture* tex)
 
 	len += Write<unsigned int>(tex->mWidth);
 	len += Write<unsigned int>(tex->mHeight);
-	len += static_cast<uint32_t>(fwrite(tex->achFormatHint,1,4,out));
+	// Write the texture format, but don't include the null terminator.
+	len += static_cast<uint32_t>(fwrite(tex->achFormatHint,sizeof(char),HINTMAXTEXTURELEN - 1,out));
 
 	if(!shortened) {
 		if (!tex->mHeight) {