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. Stack corruption - STRANGE PROBLEM!!

Stack corruption - STRANGE PROBLEM!!

Scheduled Pinned Locked Moved C / C++ / MFC
data-structureshelp
7 Posts 6 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.
  • S Offline
    S Offline
    Shailesh H
    wrote on last edited by
    #1

    I am launching a worker thread . Inside the thread function i open CDialog's using DoModal().There is no problem in the first launch of the thread. But in second launch the stack seems to get corrupted, the CString member variable of the Dialogs show values like "C4".. "D5" etc before even they r initialized in the Dialogs contructor(i.e when the execution is within the constructor).Even after Initializing the dialog's CString variables in constructor the variables do not get initialized, they still show "C4" etc psuedo code below: line 1:CWelcomeDlg dlg; line 2:dlg.SetTitle(strDialogTitle);//Set the dialog Title line 3 :ret = dlg.DoModal();//show dialog //Constructor CWelcomeDlg::CWelcomeDlg(CWnd* pParent /*=NULL*/) : CDialog(CWelcomeDlg::IDD, pParent) { m_strData1=_T("");---->m_strData1 shows value "C4" and cannot b initialized to empty string. m_strData2=_T("");--->m_strData1 shows value "C4" m_strData3=_T("");--->m_strData1 shows value "C4" }

    S M N 2 4 Replies Last reply
    0
    • S Shailesh H

      I am launching a worker thread . Inside the thread function i open CDialog's using DoModal().There is no problem in the first launch of the thread. But in second launch the stack seems to get corrupted, the CString member variable of the Dialogs show values like "C4".. "D5" etc before even they r initialized in the Dialogs contructor(i.e when the execution is within the constructor).Even after Initializing the dialog's CString variables in constructor the variables do not get initialized, they still show "C4" etc psuedo code below: line 1:CWelcomeDlg dlg; line 2:dlg.SetTitle(strDialogTitle);//Set the dialog Title line 3 :ret = dlg.DoModal();//show dialog //Constructor CWelcomeDlg::CWelcomeDlg(CWnd* pParent /*=NULL*/) : CDialog(CWelcomeDlg::IDD, pParent) { m_strData1=_T("");---->m_strData1 shows value "C4" and cannot b initialized to empty string. m_strData2=_T("");--->m_strData1 shows value "C4" m_strData3=_T("");--->m_strData1 shows value "C4" }

      S Offline
      S Offline
      Shailesh H
      wrote on last edited by
      #2

      Pls note that the above problem is seen only in the Release mode

      C R 2 Replies Last reply
      0
      • S Shailesh H

        I am launching a worker thread . Inside the thread function i open CDialog's using DoModal().There is no problem in the first launch of the thread. But in second launch the stack seems to get corrupted, the CString member variable of the Dialogs show values like "C4".. "D5" etc before even they r initialized in the Dialogs contructor(i.e when the execution is within the constructor).Even after Initializing the dialog's CString variables in constructor the variables do not get initialized, they still show "C4" etc psuedo code below: line 1:CWelcomeDlg dlg; line 2:dlg.SetTitle(strDialogTitle);//Set the dialog Title line 3 :ret = dlg.DoModal();//show dialog //Constructor CWelcomeDlg::CWelcomeDlg(CWnd* pParent /*=NULL*/) : CDialog(CWelcomeDlg::IDD, pParent) { m_strData1=_T("");---->m_strData1 shows value "C4" and cannot b initialized to empty string. m_strData2=_T("");--->m_strData1 shows value "C4" m_strData3=_T("");--->m_strData1 shows value "C4" }

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

        don't do UI in the worker thread; ask the main application thread to do it by sending messages and using event and things like that to keep everything synchronized. read : http://www.flounder.com/workerthreads.htm[^] and everything thread related on that site.

        This signature was proudly tested on animals.

        1 Reply Last reply
        0
        • S Shailesh H

          I am launching a worker thread . Inside the thread function i open CDialog's using DoModal().There is no problem in the first launch of the thread. But in second launch the stack seems to get corrupted, the CString member variable of the Dialogs show values like "C4".. "D5" etc before even they r initialized in the Dialogs contructor(i.e when the execution is within the constructor).Even after Initializing the dialog's CString variables in constructor the variables do not get initialized, they still show "C4" etc psuedo code below: line 1:CWelcomeDlg dlg; line 2:dlg.SetTitle(strDialogTitle);//Set the dialog Title line 3 :ret = dlg.DoModal();//show dialog //Constructor CWelcomeDlg::CWelcomeDlg(CWnd* pParent /*=NULL*/) : CDialog(CWelcomeDlg::IDD, pParent) { m_strData1=_T("");---->m_strData1 shows value "C4" and cannot b initialized to empty string. m_strData2=_T("");--->m_strData1 shows value "C4" m_strData3=_T("");--->m_strData1 shows value "C4" }

          N Offline
          N Offline
          Nelek
          wrote on last edited by
          #4

          Is the second launch waiting for the first to be ended? If not... you may have problems with DoModal () multiple calls. Would not be better to use ModalLess dialogs?

          Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpfull answers is nice, but saying thanks can be even nicer.

          1 Reply Last reply
          0
          • S Shailesh H

            Pls note that the above problem is seen only in the Release mode

            C Offline
            C Offline
            Code o mat
            wrote on last edited by
            #5

            Does your program otherwise work ok? If yes, then take into account that the debugger might fool you, afterall, it IS a release build, we sadly have seen such "odd" occurances many times when trying to debug release builds, the "tooltips" VS displays when pointing at a variable during runtime to show you the value of the variable (or the quick watch window, or or or...) would show all kinds of exotic, strange values which clearly aren't there (you can for example check this if you bring up a message box showing the value you are interested in formatted into a string, in your case, the string itself i guess...). p.s: ah yes, and as others said, try to avoid creating secondary UI threads because they mean a lot of trouble...

            > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <

            modified on Tuesday, December 22, 2009 12:36 PM

            1 Reply Last reply
            0
            • S Shailesh H

              Pls note that the above problem is seen only in the Release mode

              R Offline
              R Offline
              Rajesh R Subramanian
              wrote on last edited by
              #6

              Shailesh H wrote:

              Pls note that the above problem is seen only in the Release mode

              Please note that you have an article to read[^]. :) In addition to that, I'd second the opinion of other poster, who asked you not to touch the UI from within a worker thread.

              “Follow your bliss.” – Joseph Campbell

              1 Reply Last reply
              0
              • S Shailesh H

                I am launching a worker thread . Inside the thread function i open CDialog's using DoModal().There is no problem in the first launch of the thread. But in second launch the stack seems to get corrupted, the CString member variable of the Dialogs show values like "C4".. "D5" etc before even they r initialized in the Dialogs contructor(i.e when the execution is within the constructor).Even after Initializing the dialog's CString variables in constructor the variables do not get initialized, they still show "C4" etc psuedo code below: line 1:CWelcomeDlg dlg; line 2:dlg.SetTitle(strDialogTitle);//Set the dialog Title line 3 :ret = dlg.DoModal();//show dialog //Constructor CWelcomeDlg::CWelcomeDlg(CWnd* pParent /*=NULL*/) : CDialog(CWelcomeDlg::IDD, pParent) { m_strData1=_T("");---->m_strData1 shows value "C4" and cannot b initialized to empty string. m_strData2=_T("");--->m_strData1 shows value "C4" m_strData3=_T("");--->m_strData1 shows value "C4" }

                2 Offline
                2 Offline
                224917
                wrote on last edited by
                #7

                Shailesh H wrote:

                line 2:dlg.SetTitle(strDialogTitle);//Set the dialog Title

                Is strDialogTitle of type CString? If then is it shared across threads? -Suhredayan

                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