2
0
Эх сурвалжийг харах

Fixes issues that prevents the app from working on a 64-bit system
Fix:
NOTE: May not be best fix

Adds new version of readArray that takes the size that reads are suppose to be performed at.
The issue is that lines 942 and 946 of Package.cpp declar vectors that contain 'unsigned long'
The read array uses the size of T (unsigned long) in this case which is 4 on a 32 bit platform and 8 on a 64
Int is also 4 bytes, but did not convert to unsigned int due to 'AnimationController' required unsigned long arrays

Hence, the read function that now can take a size, so long as the readSize > sizeof(T) (ASSERTED)

Brandon Slack 14 жил өмнө
parent
commit
9b04cf0517

+ 22 - 2
gameplay/src/Package.cpp

@@ -94,6 +94,26 @@ bool Package::readArray(unsigned int* length, std::vector<T>* values)
     return true;
     return true;
 }
 }
 
 
+template <class T>
+bool Package::readArray(unsigned int* length, std::vector<T>* values, unsigned int readSize)
+{
+    assert(sizeof(T) >= readSize);
+
+    if (!read(length))
+    {
+        return false;
+    }
+    if (*length > 0 && values)
+    {
+        values->resize(*length);
+        if (fread(&(*values)[0], readSize, *length, _file) != *length)
+        {
+            return false;
+        }
+    }
+    return true;
+}
+
 std::string readString(FILE* fp)
 std::string readString(FILE* fp)
 {
 {
     unsigned int length;
     unsigned int length;
@@ -935,7 +955,7 @@ Animation* Package::readAnimationChannel(Scene* scene, Animation* animation, con
     unsigned int interpolationCount;
     unsigned int interpolationCount;
 
 
     // read key times
     // read key times
-    if (!readArray(&keyTimesCount, &keyTimes))
+    if (!readArray(&keyTimesCount, &keyTimes, sizeof(unsigned int)))
     {
     {
         LOG_ERROR_VARG("Failed to read %s for %s: %s", "keyTimes", "animation", id);
         LOG_ERROR_VARG("Failed to read %s for %s: %s", "keyTimes", "animation", id);
         return NULL;
         return NULL;
@@ -963,7 +983,7 @@ Animation* Package::readAnimationChannel(Scene* scene, Animation* animation, con
     }
     }
     
     
     // read interpolations
     // read interpolations
-    if (!readArray(&interpolationCount, &interpolation))
+    if (!readArray(&interpolationCount, &interpolation, sizeof(unsigned int)))
     {
     {
         LOG_ERROR_VARG("Failed to read %s for %s: %s", "interpolation", "animation", id);
         LOG_ERROR_VARG("Failed to read %s for %s: %s", "interpolation", "animation", id);
         return NULL;
         return NULL;

+ 12 - 0
gameplay/src/Package.h

@@ -263,6 +263,18 @@ private:
     template <class T>
     template <class T>
     bool readArray(unsigned int* length, std::vector<T>* values);
     bool readArray(unsigned int* length, std::vector<T>* values);
 
 
+    /**
+     * Reads an array of values and the array length from the current file position.
+     * 
+     * @param length A pointer to where the length of the array will be copied to.
+     * @param values A pointer to the vector to copy the values to. The vector will be resized if it is smaller than length.
+     * @param readSize The size that reads will be preformed at, size must be the same as or smaller then the sizeof(T)
+     * 
+     * @return True if successful, false if an error occurred.
+     */
+    template <class T>
+    bool readArray(unsigned int* length, std::vector<T>* values, unsigned int readSize);
+    
     /**
     /**
      * Reads 16 floats from the current file position.
      * Reads 16 floats from the current file position.
      *
      *