Stack corruption - STRANGE PROBLEM!!
-
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" }
-
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" }
Pls note that the above problem is seen only in the Release mode
-
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" }
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.
-
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" }
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.
-
Pls note that the above problem is seen only in the Release mode
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
-
Pls note that the above problem is seen only in the Release mode
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
-
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" }