Click to See Complete Forum and Search --> : WaitForMultipleObjects error
heyrung
March 3rd, 2006, 01:37 PM
Hi
I have this code
dwHandleSignaled = WaitForMultipleObjects(EVENT_HANDLES, m_hHandlesToWaitFor, FALSE, INFINITE);
and my m_hHandlesToWaitFor has these threads
m_hHandlesToWaitFor[0] = m_hThreadCloseEvent;
m_hHandlesToWaitFor[1] = m_hThreadScanEvent;
I ran the program (set break points and single step thru), and before it ended running, it called WaitForMultipleObjects as above , and I got this error saying
"Unhandled Exception in MyProgram.exe 0xC0000005: Access Violation"
so I hit OK on the error message window, it went to
void CNiMatrix::GetSize (unsigned int& _rows, unsigned int& _cols) const {
_rows = rows;
_cols = cols;
}
(CNiMatrix is add on control I got from National Instrument's MeasurementStudio software)
I dont know why this error is happened...you guys have any idea?
by the way, I also set break point everywhere in my code that use the method GetSize, but it doesnt get there when I got that error.
thanks
Siddhartha
March 3rd, 2006, 02:00 PM
You need to post the code in-around the call for WFMO, and including the same.
Additionally, what kind of an object is m_hHandlesToWaitFor?
Post it's declaration.
Presuming it is an array, are you sure all elements are valid handles before you call WFMO using the same?
Siddhartha
March 3rd, 2006, 02:01 PM
[ redirected ]
Regards,
Siddhartha
heyrung
March 3rd, 2006, 02:43 PM
Hi
The declaration is
#define EVENT_HANDLES 2
HANDLE m_hHandlesToWaitFor[EVENT_HANDLES];
Here's the function that calls it
UINT CDeviceMgr::Thread()
{
// the index of the handle signaled in our waitForMultipleObjects
DWORD dwHandleSignaled;
// the current status of our call
E_STATUS E_Sts = E_OK;
// DEAD CODE
long lSave = 0;
// while not signalled to soft stop
while(!m_bThreadStopFlag)
{
// sleep till event signalled
// waiting on Close Event (0) or Scan Event (1)
dwHandleSignaled = WaitForMultipleObjects(EVENT_HANDLES, m_hHandlesToWaitFor,
FALSE, INFINITE);
// check the event handle
switch( dwHandleSignaled )
{
// close event
case WAIT_OBJECT_0 :
{
TRACE("Close event\n");
break;
}
// Scan Event
case WAIT_OBJECT_0 + 1:
{
TRACE("Start scan event\n");
// set our flag that we are scanning
m_bScanOn = TRUE;
// setup our motion controller
E_Sts = MotionControllerSetup(m_bInitializeMC);
// if we have encountered an error, stop
if(E_Sts != E_OK)
{
// setup error and send to app
m_Status.m_bScanOn = FALSE;
m_Status.m_ErrSts = E_Sts;
PostMessage(m_hDisplay, WM_SCANMSG_ERROR, 0, 0);
// why continue and not break???
continue;
}
// setup scan device
if (m_pScanParamData->m_Scan_type != TIME_DOMAIN_SCAN) // if use SA
E_Sts = ScanDeviceSetup();
else // if use Osc
E_Sts = OscilloscopeSetup();
// if we have encountered an error, stop
if( E_Sts != E_OK)
{
// setup error and send to app
m_Status.m_bScanOn = FALSE;
m_Status.m_ErrSts = E_Sts;
PostMessage(m_hDisplay, WM_SCANMSG_ERROR, 0, 0);
break;
}
// setup scan device
E_Sts = SetMotionParams();
// if we have encountered an error, stop
if( E_Sts != E_OK)
{
// setup error and send to app
m_Status.m_bScanOn = FALSE;
m_Status.m_ErrSts = E_Sts;
PostMessage(m_hDisplay, WM_SCANMSG_ERROR, 0, 0);
break;
}
// if we are using a signal generator
if(m_pScanParamData->m_bUseSignalGenerator == TRUE)
{
// setup signal generator
E_Sts = SignalGeneratorSetup();
// if we have encountered an error, stop
if( E_Sts != E_OK)
{
// setup error and send to app
m_Status.m_bScanOn = FALSE;
m_Status.m_ErrSts = E_Sts;
PostMessage(m_hDisplay, WM_SCANMSG_ERROR, 0, 0);
break;
}
}
// if discrete scan
if(m_pScanParamData->m_Scan_type == SINGLE_FREQ)
{
// process discrete scan
E_Sts = ScanDiscreteFreq();
}
// if band scan
else if (m_pScanParamData->m_Scan_type == BAND_FREQ)
{
// band frequency processing
E_Sts = ScanBandFreq();
}
else if (m_pScanParamData->m_Scan_type == TIME_DOMAIN_SCAN)
{
//scan osc
E_Sts = ScanTimeDomainData();
}
//should have else here
// if there was an error, post it
if( E_Sts != E_OK )
{
m_Status.m_bScanOn = FALSE;
m_Status.m_ErrSts = E_Sts;
PostMessage(m_hDisplay, WM_SCANMSG_ERROR, 0, 0);
break;
}
// post autosave message to display update
PostMessage(m_hDisplay, WM_DISPLAY_UPDATE, SAVE_FILE, END_OF_SCAN);
// uninit osc if it's opened
OscUnInitialize(&Drm,&Dvi);
// post scan complete notification to app
PostMessage(m_hDisplay, WM_SCANMSG_COMPLTE, 0, 0);
}
break;
default:
break;
}
}
// thread is stopped, we are exiting
m_bThreadStopped = TRUE;
return 0;
}
Thanks
Siddhartha
March 3rd, 2006, 02:48 PM
So, where are you creating the handles and where are you assigning them to the elements inside that array?
Unless the handles are created before you use them in WFMO, the elements of the array contain junk values and are bound to crash.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.