|
-
January 11th, 2010, 10:53 AM
#1
Run-Time Check Failure #2
Hi - I've tried searching for a solution (or a means to find one) for my problem. I have several classes that derive from a generic "Logging" class - it allows me to easily log diagnostic output to NULL (burn the messages) or display or to file. The program is multithreaded and works fine if I don't display any debug (ie, don't call the functions below), however one particular thread seems to cause a "Run-Time Check Failure #2 - Stack around the variable sOut was corrupted" all the time. The thread is responsible to transmitting data over a serial port, and it only reports what it's currently writing to the port.
Here is are the functions, DebugOut is the function that's throwing the error, the other function is just to illustrate what DebugOut is doing (formatting the string, dropping it into a linked list and messaging the UI thread to grab data)
Code:
void CLogging::DebugOut(LPCTSTR szFmt, ...)
{
CString sOut;
va_list vars;
static BOOL OnlyOnce = FALSE;
while(OnlyOnce != FALSE)
Sleep(10);
OnlyOnce = TRUE;
va_start(vars, szFmt);
sOut.FormatV(szFmt, vars);
va_end(vars);
LogOutput(sOut);
OnlyOnce = FALSE;
}
void CLogging::LogOutput(LPCTSTR szOut)
{
// Output status message on the main window
CSingleLock cs(&m_Crit);
cs.Lock();
m_sMsgList.AddTail( szOut );
::PostMessage(m_hWndMain,WM_DEBUGOUTPUT,0,0);
}
I added the "OnlyOnce" static var to try and eliminate a thread-reentrancy problem (just in case another thread is calling the same function - it didn't make a difference)
Any help is greatly appreciated!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|