[fixed]getAttributeValueAsInt wrong ret-value for large ints

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
squisher
Competition winner
Posts: 91
Joined: Sat May 17, 2008 2:23 am
Contact:

[fixed]getAttributeValueAsInt wrong ret-value for large ints

Post by squisher »

I have the following node in a wchar_t XML file:

Code: Select all

<element_position id1="152722522" id2="3" x="301" y="118" />
I created an IXMLReader with IFileSystem->createXMLReader(...), and use getAttributeValueAsInt to read all 4 attributes.

It reads id2, x, and y just fine, but returns 152722528 instead of 152722522 for id1. (If I just use getAttributeValue to get the string, it correctly returns 152722528). I suspect that this is because getAttributeValueAsFloat is used and thus some rounding errors are occurring. id1 is an id and needs to be exact or my program crashes.

This is what I use as a workaround for now:

Code: Select all

    #include <sstream>
    template<typename T>
    T getAttributeValueAs(IXMLReader* xml, const wchar_t* attribute)
    {
        stringc valueString = xml->getAttributeValue(attribute);
        if (valueString.size() <= 0) return ~0;

        stringstream valueStream;
        valueStream << valueString.c_str();
        T value = ~0;
        valueStream >> value;
        return value;
    }
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Wow, sounds like a bad bug. I can reproduce it in 1.7, but I took too long writing the test to find it (stumpled upon another problem on the way) and must sleep now. I hope I find more time next week.

Thanks for reporting this!
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Should be fixed now in the 1.7 svn branch. It was indeed because it used the floats for some reason.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply