Skip to main content
gamedev.net
🔒 Locked

[C++]std::merge runtime error

Started by sheep19 Apr 11, 2009 at 12:42 PM 1 replies 700+ views
Original Post
sheep19
sheep19
I want to merge to vectors of Points. in some function:

// storage for the points
//PointStorage is a typedef for std::vector<Point>
	PointStorage spr1Points, spr2Points;
	
	// add points
	AddPixelPoints(spr1, spr1Points);
	AddPixelPoints(spr2, spr2Points);

	PointStorage points;
	std::merge( spr1Points.begin(), spr1Points.end(), spr2Points.begin(), spr2Points.end(), points.begin() );


Point defines the < and == operator. I get: Microsoft Visual Studio C Runtime Library has detected a fatal error in FigureFight.exe Break | Continue And it takes me to that STL code (which I can't figure btw):

/*<-.....code */
#if _SECURE_SCL
template<class _InIt1, class _InIt2, class _OutIt>
inline
	_OutIt _Merge(_InIt1 _First1, _InIt1 _Last1,
		_InIt2 _First2, _InIt2 _Last2, _OutIt _Dest,
		random_access_iterator_tag, _Range_checked_iterator_tag)
	{	// copy merging ranges, both using operator<
	// for range checked iterators, this will make sure there is enough space
	->HERE: _OutIt _Result = _Dest + (_Last1 - _First1) + (_Last2 - _First2);
	_Merge(_First1, _Last1, _First2, _Last2, _CHECKED_BASE(_Dest),
		forward_iterator_tag(), _Range_checked_iterator_tag());
	return _Result;
	}
/* code.....-> */
#endif

spr1Points and spr2Points contain a lot of objects btw. spr1Points's size is 14647 spr2Points's size is 7686
SiCrane
SiCrane
points.begin() isn't a valid output iterator for std::merge(). You probably want a std::back_inserter(points). Alternately, you could resize() points to the size of spr1 + spr2 and use begin().

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.