Problem with CCTMXTiledMap

So I believe the issue relates to the atoi(char* string) function that is used inside Value (CCValue.h) when it tries to convert the string GID “2147483649”, for example, to an int on windows (well actually MSVC compiler and standard lib) it converts and truncates to INT_MAX (0x7fff ffff). The other platforms where it works correctly .

I’ll file an issue in github. I’m not sure what the solution is? Possibly add a asLong() or asUInt() to Value. I’m guessing this is the only place (TMX file parsing) where this issue arises.

I’m looking into seeing if I can give you a line of code(s) to change to fix the issue.

If you want it to work on windows for now you’ll probably have to convert or make a copy of your .tmx into one of the other export formats (base64 or zlib).

Edit: I fixed a specific issue.

// the XML parser calls here with all the elements
void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
{
// ...
// Approx. Line 320 (CCTMXXMLParser.cpp)
// Erroneous
//uint32_t gid = static_cast<uint32_t>(attributeDict["gid"].asInt());
//
// #1 don't need to change CCValue.h (use string to unsigned long)
const char * gidStr = attributeDict["gid"];
uint32_t gid = strtoul(gidStr, NULL, 10);
//
// #2 need to add a new asUnsignedInt() to VAlue
//uint32_t gid = static_cast<uint32_t>(attributeDict["gid"].asUnsignedInt());
}

If you want to go with #2 you can add the following to Value’s impl

// inside CCValue.cpp (removed braces '{', '}' for brevity)
unsigned int Value::asUnsignedInt() const {
    CCASSERT(...);
    if (_type == Type::INTEGER) 
        return _field.intVal;
    if (_type == Type::BYTE)
        return _field.byteVal;
    if (_type == Type::STRING)
        return static_cast<unsigned int>(strtoul(_field.strVal->c_str(), NULL, 10));
    if (_type == Type::FLOAT)
        return static_cast<unsigned int>(_field.floatVal);
    if (_type == Type::DOUBLE)
        return static_cast<unsigned int>(_field.doubleVal);
    if (_type == Type::BOOLEAN)
        return _field.boolVal ? 1 : 0;
    return 0;
}

Let me know if this works for you.