Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. crash with vectors in Release

crash with vectors in Release

Scheduled Pinned Locked Moved C / C++ / MFC
helpdata-structuresquestionannouncement
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    VC Maniac
    wrote on last edited by
    #1

    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!!

    _ 1 Reply Last reply
    0
    • V VC Maniac

      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!!

      _ Offline
      _ Offline
      _AnsHUMAN_
      wrote on last edited by
      #2

      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_

      V 1 Reply Last reply
      0
      • _ _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_

        V Offline
        V Offline
        VC Maniac
        wrote on last edited by
        #3

        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

        D 1 Reply Last reply
        0
        • V VC Maniac

          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

          D Offline
          D Offline
          David Schumaker
          wrote on last edited by
          #4

          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

          M 1 Reply Last reply
          0
          • D 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

            M Offline
            M Offline
            Maximilien
            wrote on last edited by
            #5

            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.

            S 1 Reply Last reply
            0
            • M Maximilien

              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.

              S Offline
              S Offline
              semitae
              wrote on last edited by
              #6

              I had the same problem when porting from VS2005 to VS2008. I avoided it using dynamic allocation something like this: std::vector *v; v = new ???; v->push_back(***) This works in both debug and release mode :)

              ^^

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups