Question : Access violation reading location on vector.push_back

I'm reading some values from an xml file which I then put in a vector. However on certain values I get this error:
First-chance exception at 0x7568df2b in app.exe: 0xC0000005: Access violation reading location 0x6e617274


It always happens on the same values but that doesn't make any sense since there's nothing really different between those that work and those that don't.
I have a class AnimationNode which has a vector<TimedRotation>, which is simply a class that holds a few values (which are always initialized). I call a function to add the values in which I do the push_back and that is where the exception happens. All values enter my function correctly.


1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
#pragma once
#include <vector>
using namespace std;
#include "TimedRotation.h"

typedef vector<TimedRotation>::const_iterator TRIT;

class AnimationNode
{
public:

	AnimationNode(tstring name);
	virtual ~AnimationNode(void);

	void AddTransformAt(int time, Float4 rotation,Float3 pivot);


	/**
	* The start of the rotations.
	*/
	TRIT TransformBegin(){return m_Rotations.begin();}
	/**
	* The end of the rotations.
	*/
	TRIT TransformEnd(){return m_Rotations.end();}

private:

	tstring m_Name;

	vector<TimedRotation> m_Rotations;

};


void AnimationNode::AddTransformAt(int time, Float4 rotation,Float3 pivot)
{
	TimedRotation tr(time,rotation,pivot,Float3(1,1,1));
	m_Rotations.push_back(tr);				// <-- ERROR HERE
	std::sort(m_Rotations.begin(),m_Rotations.end(),TimedRotationSorter());
}


When I check where the error actually occurs it's here in xmemory:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
_STD_BEGIN
		// TEMPLATE FUNCTION _Allocate
template<class _Ty> inline
	_Ty _FARQ *_Allocate(_SIZT _Count, _Ty _FARQ *)
	{	// check for integer overflow
	if (_Count <= 0)
		_Count = 0;
	else if (((_SIZT)(-1) / _Count) < sizeof (_Ty))
		_THROW_NCEE(std::bad_alloc, NULL);

		// allocate storage for _Count elements of type _Ty
	return ((_Ty _FARQ *)::operator new(_Count * sizeof (_Ty)));      // <-- ERROR HERE
	}

With _Count having the value 52442120



I attached the xml file, for example, reading the values of Bip01 Spine works, those of Bip01 R Thigh cause the exception.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
	<anim name='Bip01 Spine'>
		<time value='5'>
			<transform rot='-1.57185 -1.36542 -0.799044 ' pivot='0.0032068 -0.00310078 0.789961'/>
		</time>
	</anim>
	<anim name='Bip01 R Thigh'>
		<time value='5'>
			<transform rot='-0.0953748 1.2315 3.08786 ' pivot='-0.0587772 -0.0409226 0.652361'/>
		</time>
	</anim>



I don't quite get this, why do some values cause this while others don't?
Anyone who can shed some light on this?


Thanks in advance.
Attachments:
 
the xml file
 

Answer : Access violation reading location on vector.push_back

Just to make sure it's not a memory size issue : are you actually storing millions of entries in the m_Rotations vector ?

If not, then a good place to start looking for memory corruption, is the memory in and around the vector.

For example, the m_Name data member, and the TimedRotation class.
Random Solutions  
 
programming4us programming4us