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. Debug assertion failed

Debug assertion failed

Scheduled Pinned Locked Moved C / C++ / MFC
debuggingperformancequestionannouncement
9 Posts 4 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.
  • R Offline
    R Offline
    Rsh
    wrote on last edited by
    #1

    How do i release the memory after reading from the CList from the head position.If i run the folowing code i get Debug assertion failed at the delete statement. void CPLayerApp::LockIt() { unsigned char data[10], mCnt,mMid; CMessage* pMess; CSingleLock singleLock(&m_SyncLock.m_mutex); CString str=""; while(1) { if(m_messList.GetCount() != 0) { singleLock.Lock(); pMess = &m_messList.GetAt(m_messList.GetHeadPosition());//m_messList is a CList pointer mCnt = pMess->m_cnt; mMid = pMess->m_mid; pMess->GetData(data); POSITION pos = m_messList.GetHeadPosition(); m_messList.RemoveHead(); delete pos; singleLock.Unlock(); if(data[0] == 0x10) { str.Format("%0x",data[0]); AfxMessageBox(str); break; } } Sleep(200); } Rsh

    R P C 3 Replies Last reply
    0
    • R Rsh

      How do i release the memory after reading from the CList from the head position.If i run the folowing code i get Debug assertion failed at the delete statement. void CPLayerApp::LockIt() { unsigned char data[10], mCnt,mMid; CMessage* pMess; CSingleLock singleLock(&m_SyncLock.m_mutex); CString str=""; while(1) { if(m_messList.GetCount() != 0) { singleLock.Lock(); pMess = &m_messList.GetAt(m_messList.GetHeadPosition());//m_messList is a CList pointer mCnt = pMess->m_cnt; mMid = pMess->m_mid; pMess->GetData(data); POSITION pos = m_messList.GetHeadPosition(); m_messList.RemoveHead(); delete pos; singleLock.Unlock(); if(data[0] == 0x10) { str.Format("%0x",data[0]); AfxMessageBox(str); break; } } Sleep(200); } Rsh

      R Offline
      R Offline
      Rage
      wrote on last edited by
      #2

      I do not see the point of your code :confused: Why using a POSITION if you delete it two lines after ? ~RaGE();

      1 Reply Last reply
      0
      • R Rsh

        How do i release the memory after reading from the CList from the head position.If i run the folowing code i get Debug assertion failed at the delete statement. void CPLayerApp::LockIt() { unsigned char data[10], mCnt,mMid; CMessage* pMess; CSingleLock singleLock(&m_SyncLock.m_mutex); CString str=""; while(1) { if(m_messList.GetCount() != 0) { singleLock.Lock(); pMess = &m_messList.GetAt(m_messList.GetHeadPosition());//m_messList is a CList pointer mCnt = pMess->m_cnt; mMid = pMess->m_mid; pMess->GetData(data); POSITION pos = m_messList.GetHeadPosition(); m_messList.RemoveHead(); delete pos; singleLock.Unlock(); if(data[0] == 0x10) { str.Format("%0x",data[0]); AfxMessageBox(str); break; } } Sleep(200); } Rsh

        P Offline
        P Offline
        Prem Kumar
        wrote on last edited by
        #3

        Actually the statement of 'delete pos' doesnt make sense !! pos is just a stack variable and its value is not necessarily a pointer.

        R 1 Reply Last reply
        0
        • P Prem Kumar

          Actually the statement of 'delete pos' doesnt make sense !! pos is just a stack variable and its value is not necessarily a pointer.

          R Offline
          R Offline
          Rsh
          wrote on last edited by
          #4

          Ok. If POSITION and pos r not required can u pls. suggest how to release the memory associated with the element in the CList after you read that? Cause RemoveHead()is not doing that. Rsh

          P 1 Reply Last reply
          0
          • R Rsh

            Ok. If POSITION and pos r not required can u pls. suggest how to release the memory associated with the element in the CList after you read that? Cause RemoveHead()is not doing that. Rsh

            P Offline
            P Offline
            Prem Kumar
            wrote on last edited by
            #5

            how abt 'delete pMess' ???

            R 1 Reply Last reply
            0
            • P Prem Kumar

              how abt 'delete pMess' ???

              R Offline
              R Offline
              Rsh
              wrote on last edited by
              #6

              No Prem, even that doesn't work.Just now i tried with that also. Its giving the same error. Rsh

              R 1 Reply Last reply
              0
              • R Rsh

                No Prem, even that doesn't work.Just now i tried with that also. Its giving the same error. Rsh

                R Offline
                R Offline
                Rage
                wrote on last edited by
                #7

                As far as I know (but I may be wrong) if you delete an Item with RemoveHead(), itreturns a pointer on the deleted item. So let´s use this to delete the already-deleted-in-the-list Item ... no ? ~RaGE();

                1 Reply Last reply
                0
                • R Rsh

                  How do i release the memory after reading from the CList from the head position.If i run the folowing code i get Debug assertion failed at the delete statement. void CPLayerApp::LockIt() { unsigned char data[10], mCnt,mMid; CMessage* pMess; CSingleLock singleLock(&m_SyncLock.m_mutex); CString str=""; while(1) { if(m_messList.GetCount() != 0) { singleLock.Lock(); pMess = &m_messList.GetAt(m_messList.GetHeadPosition());//m_messList is a CList pointer mCnt = pMess->m_cnt; mMid = pMess->m_mid; pMess->GetData(data); POSITION pos = m_messList.GetHeadPosition(); m_messList.RemoveHead(); delete pos; singleLock.Unlock(); if(data[0] == 0x10) { str.Format("%0x",data[0]); AfxMessageBox(str); break; } } Sleep(200); } Rsh

                  C Offline
                  C Offline
                  Chad Koehler
                  wrote on last edited by
                  #8

                  :confused: Are you just trying to iterate through the list? If so, there are easier ways, I will elaborate if needed. Otherwise, just remove the line that says 'delete pos;'. As was stated this is a variable declared on the stack. Trying to delete it will cause debug assertion errors. (Worse yet in release mode)

                  R 1 Reply Last reply
                  0
                  • C Chad Koehler

                    :confused: Are you just trying to iterate through the list? If so, there are easier ways, I will elaborate if needed. Otherwise, just remove the line that says 'delete pos;'. As was stated this is a variable declared on the stack. Trying to delete it will cause debug assertion errors. (Worse yet in release mode)

                    R Offline
                    R Offline
                    Rsh
                    wrote on last edited by
                    #9

                    what exactly i want is, to read the elemnts from the headposition in Clist and immediately after reading,would like to delete the already read element from the list & also release the memory that was associated with the deleted element. Can anybody pls. elaborate on this The code is as follows void CPLayerApp::LockIt() { unsigned char data[10],mCnt,mMid; unsigned char *ptr; CMessage* pMess; CMessage* delMess; CSingleLock singleLock(&m_SyncLock.m_mutex); CString str=""; while(1) { if(m_messList.GetCount() != 0) { singleLock.Lock(); pMess = &m_messList.GetAt(m_messList.GetHeadPosition()); mCnt = pMess->m_cnt; mMid = pMess->m_mid; pMess->GetData(data); //POSITION pos = m_messList.GetHeadPosition(); m_messList.RemoveHead(); delMess= &m_messList.RemoveHead(); //pMess=(CMessage*)m_messList.RemoveHead(); delete delMess; singleLock.Unlock(); if(data[0] == 0x10) { str.Format("%0x",data[0]); AfxMessageBox(str); break; } } Sleep(200); }:( Rsh

                    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