Loading and saving a model in the Model Editor changes decimal digits: incorrect round-trip conversions

Issue #150 resolved
Carsten Fuchs
created an issue

When a weapon model (e.g. Shotgun_v.cmdl) is loaded in the Model Editor and immediately saved again without any changes, the resulting .cmdl file is different from the original: some floating-point numbers are converted to a slightly different decimal string as before.

This happens despite our careful efforts to avoid exactly this problem; in fact, the related assert(prec <= MAX_DIGITS10) in function serialize() in file Libs/Models/Model_cmdl.cpp triggers.

The attached test case reproduces this problem.

At this time, it looks as if this is a platform- or compiler-specific issue: I have not been able to reproduce the issue with g++ under Ubuntu 14.04, but reliably with '''Visual C++ 2012''' (Express Edition).

Comments (5)

  1. Carsten Fuchs reporter

    As explained in the articles at

    this problem is likely due to some bugs in older releases of Visual C++.

    As we're going to upgrade to a recent release of Visual C++ in the near future anyway, I don't think that it is economic to attempt to come up with any custom fixes for this problem.

  2. Carsten Fuchs reporter

    To summarize the current state:

    There is a bug left in Microsoft's iostream implementation up to Visual C++ 2015 (I've filed a report at https://connect.microsoft.com/VisualStudio/feedback/details/1540816 and via email).

    It seems that only the conversion from string to float with iostream is affected; the related C functions and converting from float to string seem to work right.

    For us, that means that - serializing data / writing files to disk works properly, - loading files that are Lua scripts works properly (Lua uses C functions), - only text files that we parse ourselves using the iostream library might be affected.

    In the latter case, the minor errors are probably irrelevant in most cases, and thus usually only noticed if: - the (undetected wrongly) loaded floats are serialized back into a file under version control, - the assert() statements in our serialize() functions trigger.

  3. Log in to comment