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

0 views
Skip to first unread message

Cafu Trac

unread,
Jul 10, 2015, 10:32:06 AM7/10/15
to cafu...@googlegroups.com
#150: Loading and saving a model in the Model Editor changes decimal digits:
incorrect round-trip conversions
---------------------+----------------------
Reporter: Carsten | Owner:
Type: defect | Status: new
Priority: normal | Milestone:
Component: other | Version: svn-head
Keywords: | Platform:
---------------------+----------------------
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).

--
Ticket URL: <http://trac.cafu.de/ticket/150>
Cafu 3D Game and Graphics Engine <http://www.cafu.de>
The open-source game engine and graphics engine for multiplayer, cross-platform, real-time 3D action.

Cafu Trac

unread,
Jul 10, 2015, 11:10:43 AM7/10/15
to cafu...@googlegroups.com
#150: Loading and saving a model in the Model Editor changes decimal digits:
incorrect round-trip conversions
----------------------+----------------------
Reporter: Carsten | Owner:
Type: defect | Status: closed
Priority: normal | Milestone:
Component: other | Version: svn-head
Resolution: wontfix | Keywords:
Platform: |
----------------------+----------------------
Changes (by Carsten):

* status: new => closed
* resolution: => wontfix


Comment:

As explained in the articles at

- http://www.exploringbinary.com
- http://www.exploringbinary.com/incorrect-round-trip-conversions-
in-visual-c-plus-plus/
- http://www.exploringbinary.com/visual-c-plus-plus-strtod-still-
broken/
- https://randomascii.wordpress.com/2013/02/07/float-precision-
revisited-nine-digit-float-portability/

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.

--
Ticket URL: <http://trac.cafu.de/ticket/150#comment:1>

Cafu Trac

unread,
Jul 10, 2015, 2:36:48 PM7/10/15
to cafu...@googlegroups.com
#150: Loading and saving a model in the Model Editor changes decimal digits:
incorrect round-trip conversions
----------------------+----------------------
Reporter: Carsten | Owner:
Type: defect | Status: reopened
Priority: normal | Milestone:
Component: other | Version: svn-head
Resolution: | Keywords:
Platform: |
----------------------+----------------------
Changes (by Carsten):

* status: closed => reopened
* resolution: wontfix =>


Comment:

Reconsidering, I rather leave this open until it is confirmed that with
newer releases of Visual C++ the problem doesn't appear.

--
Ticket URL: <http://trac.cafu.de/ticket/150#comment:2>

Cafu Trac

unread,
Jul 15, 2015, 5:48:37 AM7/15/15
to cafu...@googlegroups.com
#150: Loading and saving a model in the Model Editor changes decimal digits:
incorrect round-trip conversions
----------------------+----------------------
Reporter: Carsten | Owner:
Type: defect | Status: reopened
Priority: normal | Milestone:
Component: other | Version: svn-head
Resolution: | Keywords:
Platform: |
----------------------+----------------------

Comment (by Carsten):

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.

--
Ticket URL: <http://trac.cafu.de/ticket/150#comment:3>

Cafu Trac

unread,
Jul 15, 2015, 3:52:28 PM7/15/15
to cafu...@googlegroups.com
#150: Loading and saving a model in the Model Editor changes decimal digits:
incorrect round-trip conversions
----------------------+---------------------------------------------
Reporter: Carsten | Owner: Carsten Fuchs <carsten.fuchs@…>
Type: defect | Status: closed
Priority: normal | Milestone:
Component: other | Version: svn-head
Resolution: fixed | Keywords:
Platform: |
----------------------+---------------------------------------------
Changes (by Carsten Fuchs <carsten.fuchs@…>):

* owner: => Carsten Fuchs <carsten.fuchs@…>
* status: reopened => closed
* resolution: => fixed


Comment:

In [changeset:"dfb148c04952433bb62ebc9676429e443ed68f72/git"]:
{{{
#!CommitTicketReference repository="git"
revision="dfb148c04952433bb62ebc9676429e443ed68f72"
Serialization: With Visual C++ <= 2015, use `atof()` for converting
strings to floats.

Closes #150.
}}}

--
Ticket URL: <http://trac.cafu.de/ticket/150#comment:4>
Reply all
Reply to author
Forward
0 new messages