crash with vectors in Release
-
-
my application crashes while I push_back a value of type POSITION. I checked the call stack. The parameter to the insert function(push_back calls insert) was something else other than POSITION type. How? What could be the problem? Please help!!
Can you post some code? Its hard to dig in to unseen BTW did you read Survive The Release Version[^]
You need to google first, if you have "It's urgent please" mentioned in your question. ;-)_AnShUmAn_
-
Can you post some code? Its hard to dig in to unseen BTW did you read Survive The Release Version[^]
You need to google first, if you have "It's urgent please" mentioned in your question. ;-)_AnShUmAn_
This code is used for holding the text selection made by the user. CCursorPos is used for holding the cursor position.
class CCursorPos
{
public:CCursorPos() { invalidate(); } CCursorPos(const CCursorPos& pos) { \*this = pos; } BOOL isValid() const { return (m\_posItem!=NULL && m\_textPos.x > -1 && m\_textPos.y > -1); } CCursorPos& operator=(const CCursorPos& pos) { ASSERT(pos.isValid()); setCursor(pos.getItem(),pos.getTextPoint()); return \*this; } BOOL operator==(const CCursorPos& pos) const { ASSERT(isValid()); ASSERT(pos.isValid()); return (getItem() == pos.getItem() && getTextPoint() == pos.getTextPoint()); } BOOL operator!=(const CCursorPos& pos) const { return !(\*this == pos); } POSITION getItem() const { ASSERT(isValid()); return m\_posItem; } const CPoint& getTextPoint() const { ASSERT(isValid()); return m\_textPos; } void invalidate() { m\_textPos.x = m\_textPos.y = -1; m\_posItem = NULL; } void setCursor(const POSITION& pos, const CPoint& ptText) { m\_textPos = ptText; m\_posItem = pos; ASSERT(isValid()); }
protected:
CPoint m\_textPos; // in view coordinates POSITION m\_posItem;
};
........
class COutlineTextView
{
.....
CCursorPos m_selStart, m_selEnd;
std::vector<POSITION> m_selection;....
};void COutlineTextView::prepareSelBounds()
{
if (m_selection.size() > 0){
m_selection.clear();
}..... POSITION pos = m\_selStart.getItem(); while(pos != NULL && pos != m\_selEnd.getItem()) { m\_selection.push\_back(pos); //CRASH HERE !!!!!! pos = getOutline()->getNext(pos); } ASSERT(pos); m\_selection.push\_back(m\_selEnd.getItem()); ...
}
The call stack: > Desktop.exe!_crt_debugger_hook(int _Reserved=3144168) Line 65 C Desktop.exe!_invalid_parameter(const wchar_t * pszExpression=0x00000000, const wchar_t * pszFunction=0x00000000, const wchar_t * pszFile=0x00000000, unsigned int nLine=0, unsigned int pReserved=0) Line 112 + 0x7 bytes C++ Desktop.exe!_invalid_parameter_noinfo() Line 125 + 0xc bytes C++ Desktop.exe!std::_Vector_const_iterator<unsigned long,std::allocator<unsigned long> >::operator+=(int _Off=0) Line 160 + 0x14 bytes C++ Desktop.exe!std::_Vector_iterator<unsigned long,std::allocator<unsigned long> >::operator+=(int _Off=0) Line 376 C++ Desktop.exe!std::_Vector_iterator<int,std::allocato
-
This code is used for holding the text selection made by the user. CCursorPos is used for holding the cursor position.
class CCursorPos
{
public:CCursorPos() { invalidate(); } CCursorPos(const CCursorPos& pos) { \*this = pos; } BOOL isValid() const { return (m\_posItem!=NULL && m\_textPos.x > -1 && m\_textPos.y > -1); } CCursorPos& operator=(const CCursorPos& pos) { ASSERT(pos.isValid()); setCursor(pos.getItem(),pos.getTextPoint()); return \*this; } BOOL operator==(const CCursorPos& pos) const { ASSERT(isValid()); ASSERT(pos.isValid()); return (getItem() == pos.getItem() && getTextPoint() == pos.getTextPoint()); } BOOL operator!=(const CCursorPos& pos) const { return !(\*this == pos); } POSITION getItem() const { ASSERT(isValid()); return m\_posItem; } const CPoint& getTextPoint() const { ASSERT(isValid()); return m\_textPos; } void invalidate() { m\_textPos.x = m\_textPos.y = -1; m\_posItem = NULL; } void setCursor(const POSITION& pos, const CPoint& ptText) { m\_textPos = ptText; m\_posItem = pos; ASSERT(isValid()); }
protected:
CPoint m\_textPos; // in view coordinates POSITION m\_posItem;
};
........
class COutlineTextView
{
.....
CCursorPos m_selStart, m_selEnd;
std::vector<POSITION> m_selection;....
};void COutlineTextView::prepareSelBounds()
{
if (m_selection.size() > 0){
m_selection.clear();
}..... POSITION pos = m\_selStart.getItem(); while(pos != NULL && pos != m\_selEnd.getItem()) { m\_selection.push\_back(pos); //CRASH HERE !!!!!! pos = getOutline()->getNext(pos); } ASSERT(pos); m\_selection.push\_back(m\_selEnd.getItem()); ...
}
The call stack: > Desktop.exe!_crt_debugger_hook(int _Reserved=3144168) Line 65 C Desktop.exe!_invalid_parameter(const wchar_t * pszExpression=0x00000000, const wchar_t * pszFunction=0x00000000, const wchar_t * pszFile=0x00000000, unsigned int nLine=0, unsigned int pReserved=0) Line 112 + 0x7 bytes C++ Desktop.exe!_invalid_parameter_noinfo() Line 125 + 0xc bytes C++ Desktop.exe!std::_Vector_const_iterator<unsigned long,std::allocator<unsigned long> >::operator+=(int _Off=0) Line 160 + 0x14 bytes C++ Desktop.exe!std::_Vector_iterator<unsigned long,std::allocator<unsigned long> >::operator+=(int _Off=0) Line 376 C++ Desktop.exe!std::_Vector_iterator<int,std::allocato
I see exactly the same problem in my code. This problem occurred when I migrated to visual studio 2008 and attempted to execute the code using a release build. The same code does not crash in debug build in VS 2008. Has anyone been able to figure out the cause of the problem? Thanks
David Schumaker
-
I see exactly the same problem in my code. This problem occurred when I migrated to visual studio 2008 and attempted to execute the code using a release build. The same code does not crash in debug build in VS 2008. Has anyone been able to figure out the cause of the problem? Thanks
David Schumaker
Good day, Were you able to fix your problem ? I'm having the same kind of problem when porting to VS2008. Thanks. Max.
This signature was proudly tested on animals.
-
Good day, Were you able to fix your problem ? I'm having the same kind of problem when porting to VS2008. Thanks. Max.
This signature was proudly tested on animals.