Release-mode only falure when comparing STL list::iterator-s
- From: "Ivan Vecerina" <INVALID_use_webform@xxxxxxxxxxxxxxxxx>
- Date: Wed, 12 Apr 2006 17:27:04 +0200
I'm coming out of one of those painful debugging sessions with an error
appearing only in release mode. Somehow a library- or compiler-generated
runtime check fails only in release mode - and it vaguely looks like a
check made by the STL implementation [reason for posting it here].
I'm using Visual Studio 2005 with the included STL implementation.
{the same code works flawlessly using gcc/Xcode and their STL}
I have a workaround (which by the way suggests this is not about corrupt
data), but I still don't understand what the reported error is supposed to
indicate.
I could not extract a small & complete cample code, but the following
should help identify which library check reports an error:
//// DATA STRUCTURES:
typedef std::pair<float,float> Pos;
struct Bone { /*...*/ }; // a link between joints
struct Skeleton
{
typedef std::list<Bone> Bones;
Bones bones;
//for each Joint (given by a pos) keep a list of connected bones:
typedef std::vector<Bones::iterator> JointBones;
typedef std::map<Pos,JointBones> Joints;
Joints joints;
};
typedef Skeleton::Bones::iterator BoneI;
//// FAILING FUNCTION:
BoneI getNextBone( Skeleton& skel, BoneI const link, Pos const curPos )
{
//-> test a potential candidate bone to return:
BoneI const pong = *data.skel.joints[ curPos ].begin();
bool ok1 = ( &*link == &*pong ); // always works [ 0 in this case ]
bool ok2 = ( link==pong ); //CRASH in release build only...
}
In Debug mode this always works. The same input data in Release mode
triggers a failure as soon as the second comparison is reached by
calling _invalid_parameter_noinfo() :
004539AD cmp dword ptr [esp+20h],edi // What's this test??
004539B1 je getNextBone+0E8h (4539B8h)
004539B3 call _invalid_parameter_noinfo (4C457Eh)
004539B8 mov edi,dword ptr [esp+24h]
004539BC cmp edi,esi //<< actual compare to get the result
The workaround in my application is to use only the first test (ok1)
instead of the second (ok2). But what is the reason that ok2 fails
in release mode?
I have only one instance of Skeleton in my program, so all iterators
refer to the same std::list. No operation should invalidate the
iterators (since I do not fiddle with the contents of skel.bones).
So what is this release-mode only runtime error trying to tell me ?
I didn't get to study the implementation of the STL, and integration
with the VC debugger seems to hide all 'internal' members, making it
more difficult to debug what looks seems to be a library runtime check
(i.e. the debugger only shows my one pointer member, while sizeof(pong)
is actually 2 or 3 pointers long (in release and debug mode, resp.).
In case this helps: the memory dump of the iterators (3 pointers) is
the following:
Release mode:
pong = { 0A17FF20, 04B6B4C0 }
link = { 04B6AD24, 04B6B478 }
Debug mode (extra first ptr is the address of the container):
pong = { 04F8C30C, 0B96F40C, 0A88E960}
link = { 04F8C30C, 0A8FE918, 0A88E8F0}
I would be delighted if someone more familiar with the internals of
the standard lib implementation of VS2005 could point me what to
look for, to find out if this is a problem of undefined behavior
in my code revealed only in very specific circumstances, or a
library/compiler issue (less likely, but I'm running out of ideas...).
Thank you,
Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
.
- Follow-Ups:
- Re: Release-mode only falure when comparing STL list::iterator-s
- From: Tom Widmer [VC++ MVP]
- Re: Release-mode only falure when comparing STL list::iterator-s -- More info
- From: Ivan Vecerina
- Re: Release-mode only falure when comparing STL list::iterator-s
- Prev by Date: Re: Preallocate ostringstream buffer
- Next by Date: Re: Release-mode only falure when comparing STL list::iterator-s -- More info
- Previous by thread: Re: Map error.
- Next by thread: Re: Release-mode only falure when comparing STL list::iterator-s -- More info
- Index(es):
Relevant Pages
|
Loading