# STL vector resize on MSVC broken?

## Recommended Posts

Prune    224
Changing the ordering of the resizes below gives me different results--if it's this way it works, if I swap some lines, it results in corrupted data. All arrays start off at size 0 except tuftGuides, which has some data and I expand it here. I read on the Web that resize() to larger size adds elements while keeping the existing ones--but this is not happening depending on how I order the below >:( The vectors hold either floats or structs of several floats, where the structs have default and copy constructors and assignment operators defined and working fine. There's no issue in Debug build. I'm using Visual Studio 2008. There's no exception thrown. A few of the vectors are class members, and the other few are local to the function. try { tuftGuides.resize(numTufts * LAYERS); invTuftSz.resize(numTufts); sineFactors.resize(numTufts); hairSecs.resize(numHairs * LAYERS); hairDia.resize(numHairs * LAYERS); hairOffsets.resize(numHairs * LAYERS); nears.resize(numHairs); } catch (...) ..... What do I do?

##### Share on other sites
rip-off    10979
Quote:
 STL vector resize on MSVC broken?

Nope [smile]

I suspect that the constructor, assignment operator or destructor for one (or more) of your aggregate types is incorrect.

Can you explain how the corrupted data manifests itself?

##### Share on other sites
Prune    224
Visually. I'm using these vectors to generate fur for rendering. Above the code I posted, I fill part of tuft guides with poisson disk sampling, and it's just using push_back() (since I don't know the number of hair positions that will be generated). In the code after what I posted, I derive the other layers.

Rearranging, such as putting the hairSecs on top, gives me screwed up hairs with what are either missing or dark sections along their length, I can't tell exactly. I could post screenshots but I don't think it would be very informative.

The vectors are of float, Float2 (see below), and Float3 (similar to Float2).

union Float2{	inline Float2(void);	inline Float2(float const, float const = 0.0f);	inline Float2(float const []);	inline Float2(Float2 const &);	inline Float2 &operator=(Float2 const &);	struct	{		float x;		float y;	};	float a[2];};inline Float2::Float2(void){}inline Float2::Float2(float const nx, float const ny) : x(nx), y(ny){}inline Float2::Float2(float const n[]) : x(n[0]), y(n[1]){}inline Float2::Float2(Float2 const &other) : x(other.x), y(other.y){}inline Float2 &Float2::operator=(Float2 const &other){	if (this == &other) return *this;	x = other.x;	y = other.y;	return *this;}

##### Share on other sites
ToohrVyk    1596
How large are you making those vectors?

##### Share on other sites
Prune    224
Couple MB for the largest one.

##### Share on other sites
visitor    643
Resize uses the default constructor but it appears your default constructor leaves the union uninitialized. Could this be a problem?

Also, I don't think you need to define a copy constructor/assignment operator if all they do is a shallow copy.