Hi all,

I have problem with vector which I can't solve.

The key function is as follows:

Code:
void CHull::computeHull(std::vector<myPoint> & aPoints, std::vector<myPoint> & aHull)
{
	// Sort given points by y-coordinate (break tie with lower x-coordinate)
	// (this is automatically done inside the sorting callback function)
	CGeomUtils::sortByY(aPoints);

	myPoint p0 = aPoints.front();

	std::vector<myPoint>::iterator start = aPoints.begin() + 1;

	// Sort points in counterclockwise order by polar angle relative to p0
	// If two or more points have the same polar angle, keep just the farthest from p0
	// (others are just the convex combination of p0 and the farthest one and we don't 
	// have to consider them since they won't be part of the hull)
	CGeomUtils::sortByAngleRelativeTo(p0, start, aPoints.end());

	int m = aPoints.size() - 1;

	// Clear output array
	aHull.clear();

	myPoint p1 = aPoints.at(1);
	myPoint p2 = aPoints.at(2);
	myPoint top;
	myPoint nextToTop;
	myPoint cur;

	aHull.push_back(p0);
	aHull.push_back(p1);
	aHull.push_back(p2);

	int size = 0;	

	for (int i = 3; i <= m; ++i)
	{
		size = aPoints.size();

		top = mHull.back();
		nextToTop = mHull.at(mHull.size() - 2);
		cur = aPoints.at(i);

		while ((td = CGeomUtils::getTurnDirection(nextToTop, top, cur)) != tLeft)
		{
			aHull.pop_back();

			// Pathological case (consider p0, p1, p2, p3 on a straight line :-))
			if (aHull.size() < 2)
				break;

			top = aHull.back();
			nextToTop = aHull.at(aHull.size() - 2);
		}

		mHull.push_back(cur);
	}
}
The problematic line which gives me Access Violation exception is the bold one, the blue coloured ones are those which involve that critical aPoints vector.

m (the upper bound of the 'for' loop) is typicaly let's say 1000 so aPoints contains 1000 myPoint elements. But the violation always occurs in the beginning, when i is e.g. 10. So I traced it, got the breakpoing before the bold line and what I inspected is that before the critical moment of the violation, size (which holds the current size of aPoints) suddenly gets some garbage value, for example 10967136, all of sudden.

I can't see there any command that would alter aPoints vector, but indeed there is something happening...

Thank you for any suggestions.