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. Heap Corruption issue

Heap Corruption issue

Scheduled Pinned Locked Moved C / C++ / MFC
3 Posts 2 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.
  • B Offline
    B Offline
    Ben Aldhouse
    wrote on last edited by
    #1

    I've got an application which has two dialogs, I use a deque and Direct2D in one dialog within a thread. Now, if I close the application via handling WM_CLOSE I have no problem but when I try and close it by clicking on 'Close Window' in the task bar or using Alt F4 I get a breakpoint triggered on

    if (!HeapFree(select_heap(block), 0, block))

    I know it's a long shot since I have given so little detail - but seeing as the difference seems to be in the way I close the app down I was hoping there might be a quick and easy fix for this. Yours hopefully, Ben *Update since I posted in this it the next door forum, this morning, by mistake: I still get the same error if the thread (and hence the direct2d drawing) isn't running. Perhaps it is something to do with the way I set up the dialogs.

    D 1 Reply Last reply
    0
    • B Ben Aldhouse

      I've got an application which has two dialogs, I use a deque and Direct2D in one dialog within a thread. Now, if I close the application via handling WM_CLOSE I have no problem but when I try and close it by clicking on 'Close Window' in the task bar or using Alt F4 I get a breakpoint triggered on

      if (!HeapFree(select_heap(block), 0, block))

      I know it's a long shot since I have given so little detail - but seeing as the difference seems to be in the way I close the app down I was hoping there might be a quick and easy fix for this. Yours hopefully, Ben *Update since I posted in this it the next door forum, this morning, by mistake: I still get the same error if the thread (and hence the direct2d drawing) isn't running. Perhaps it is something to do with the way I set up the dialogs.

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Isn't the WM_CLOSE message being sent whether you terminate the app via Task Manager or by using Alt+F4?

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

      B 1 Reply Last reply
      0
      • D David Crow

        Isn't the WM_CLOSE message being sent whether you terminate the app via Task Manager or by using Alt+F4?

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

        B Offline
        B Offline
        Ben Aldhouse
        wrote on last edited by
        #3

        Thanks for your reply! I don't know, to be honest. The problem was occurring when I AltF4ed or clicked on Close Window but not when I clicked on my 'Exit' button. However, it looks like it was a corrupt memory problem I had with a member variable I'd assigned to the heap and was using to pass data between threads. I've changed the communication to the following: In the sending thread:

        ControlDlg \* pParent = (ControlDlg \*) this->GetParent();
        ColourAlphaEnvelope \* s = new ColourAlphaEnvelope;
        \*s = m\_ColourEnvelope;
        pParent->PostMessage(CM\_COLOURBOUNDS, reinterpret\_cast<WPARAM>(s));
        

        and in the recieving dialog I used

        afx_msg LRESULT CRectArtDlg::OnCmColourbounds(WPARAM wParam, LPARAM lParam)
        {
        std::auto_ptr<ColourAlphaEnvelope> s(reinterpret_cast<ColourAlphaEnvelope*>(wParam));
        m_colourEnvelope = *s;
        return 0;
        }

        I bet there are dozens of better ways of doing this (not least since a quick Google reveals that auto_ptr is depracated) but I haven't had a crash and the compiler isn't telling me there is a memory leak.

        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