raprapbautista10 / webgl-loader

Automatically exported from code.google.com/p/webgl-loader
0 stars 1 forks source link

MSVC Compile Problems #30

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Cannot compile with the MSC (Microsoft C Compiler).

The following errors come up:

1. Undeclared identifier 'HUGE_VALF' in optimize.h
2. Undefined function 'strtof()' in mesh.h

The following warnings come up (on warning level 3):

3. 'static_cast' : truncation of constant value utf8.h (x3)
4. 'fopen' : function may be unsafe in mesh.h and objcompress.cc
5. '=' : conversion from 'const float' to 'int', possible loss of data in mesh.h
6. '=' : truncation from 'double' to 'float' in mesh.h  
7. 'argument' : conversion from 'const size_t' to 'float', possible loss of 
data in optimize.h

The following changes should fix these errors/warnings:
1 and 2. Add the following to base.h:
    #ifdef _MSC_VER
    union _MSVC_EVIL_FLOAT_HACK { unsigned __int8 Bytes[4]; float Value; };
    const static union _MSVC_EVIL_FLOAT_HACK _INFINITY_HACK = {{0x00, 0x00, 0x80, 0x7F}};
    #define HUGE_VALF (_INFINITY_HACK.Value)
    // Note: "#define HUGE_VALF (1e25f * 1e25f)" may work as well instead of the above 3 lines
    static inline float strtof(const char * str, char ** endPtr) {
      double d = strtod(str, endPtr);
      return (float)((d > 0 && (d > FLT_MAX || d < FLT_MIN)) ? HUGE_VALF : ((d < 0 && (d < -FLT_MAX || d > -FLT_MIN)) ? -HUGE_VALF : d));
    }
    #endif

3. Switch the static_cast<char> to just a normal char cast.
4. Add "#define _CRT_SECURE_NO_WARNINGS" before any includes in base.h and 
mesh.h
5. Add an int cast:                    ret.decodeOffsets[i] = (int)(maxPosition 
* bounds.mins[i] / scale);
6. Add an "f" after the decimal value: ret.decodeScales[i] = 1.0f / 511;
7. Add a float cast:                   const float valence_boost = 
powf((float)active_tris, -kValenceBoostPower);

Going to warning level 4 introduces 18 more warnings not fixed with the above.

Original issue reported on code.google.com by j...@coderforlife.com on 1 Mar 2012 at 12:52