-
April 16th, 2010, 10:53 AM
#1
CSingleLock Instantiation gets a Debug Assert
I'm getting a debug assert at the instantiation of a CSingleLock in the situation shown below
Code:
size_t CErrorNotifier::CImplementation::GetNoOfErrorsActualyStored(void) const
{
size_t NoOfErrorsActualyStored;
CSingleLock LocalSync(&m_Sync); //m_Sync is a CSemaphore-object inside the CErrorNotifier::CImplementation-object
LocalSync.Lock();
NoOfErrorsActualyStored= m_ActualNoOfErrorsStored;
LocalSync.Unlock();
return NoOfErrorsActualyStored;
}
The problem shows up in IsDerivedFrom() during debugging:
Code:
BOOL CRuntimeClass::IsDerivedFrom(const CRuntimeClass* pBaseClass) const
{
ASSERT(this != NULL);
ASSERT(AfxIsValidAddress(this, sizeof(CRuntimeClass), FALSE));
ASSERT(pBaseClass != NULL);
ASSERT(AfxIsValidAddress(pBaseClass, sizeof(CRuntimeClass), FALSE));
// simple SI case
const CRuntimeClass* pClassThis = this;
while (pClassThis != NULL)
{
if (pClassThis == pBaseClass)
return TRUE;
#ifdef _AFXDLL
pClassThis = (*pClassThis->m_pfnGetBaseClass)();
#else
pClassThis = pClassThis->m_pBaseClass;
#endif
}
return FALSE; // walked to the top, no match
}
The condition if (pClassThis == pBaseClass) is never met although the m_lpszClassName member of both pClassThis and pBaseClass are the same: "CSyncObject". Under what circumstances can there be different CRuntimeClass Instances?
-
April 20th, 2010, 11:31 AM
#2
Re: CSingleLock Instantiation gets a Debug Assert
When I described the problem some days ago I forgot to mention that CErrorNotifier is part of a DLL. At that time I wasn't aware of the following: The problem occurs when the function shown (GetNoOfErrorsActualyStored()) is called from outside the DLL. When it is called from another function of the same DLL everything works as expected. Does anybody has a clue what the problem might be?
-
April 22nd, 2010, 04:47 PM
#3
Re: CSingleLock Instantiation gets a Debug Assert
Are the DLL and the "outside" both compiled with the same version of MFC and the same version of flags for VS?
-
April 27th, 2010, 01:51 AM
#4
Re: CSingleLock Instantiation gets a Debug Assert
@MikeAThon:
Are the DLL and the "outside" both compiled with the same version of MFC
Yes, VC6
and the same version of flags for VS
Yes, as far as I can see:
Code:
"Outside":
- Compiler-Options
/nologo /MTd /W3 /Gm /GR /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /FR"C:\_JOBS\CurrentStuff\_Intermediates\ETACtrlComponents\\" /Fo"C:\_JOBS\CurrentStuff\_Intermediates\ETACtrlComponents\\" /Fd"C:\_JOBS\CurrentStuff\_Intermediates\ETACtrlComponents\\" /FD /GZ /c
- Linker-Options
/nologo /subsystem:windows /incremental:yes /pdb:"C:\_JOBS\CurrentStuff\_Products\ETACtrlComponents\ETACtrl.pdb" /debug /machine:I386 /out:"C:\_JOBS\CurrentStuff\_Products\ETACtrlComponents\ETACtrl.exe" /pdbtype:sept
DLL:
-Compiler-Options:
/nologo /MTd /W3 /Gm /GR /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "TYPELIBSPECTROSCOPICDEVICES_EXPORTS" /D "_WINDLL" /FR"C:\_JOBS\CurrentStuff\_Intermediates\ETACtrlComponents\\" /Fo"C:\_JOBS\CurrentStuff\_Intermediates\ETACtrlComponents\\" /Fd"C:\_JOBS\CurrentStuff\_Intermediates\ETACtrlComponents\\" /FD /GZ /c
-Linker-Options:
/nologo /dll /incremental:yes /pdb:"C:\_JOBS\CurrentStuff\_Products\ETACtrlComponents\SpectroscopicDevices.pdb" /debug /machine:I386 /out:"C:\_JOBS\CurrentStuff\_Products\ETACtrlComponents\SpectroscopicDevices.dll" /implib:"C:\_JOBS\CurrentStuff\_Products\ETACtrlComponents\SpectroscopicDevices.lib" /pdbtype:sept
-
April 28th, 2010, 04:24 AM
#5
Re: CSingleLock Instantiation gets a Debug Assert
Originally Posted by greve
I'm getting a debug assert at the instantiation of a CSingleLock in the situation shown below
...
The problem shows up in IsDerivedFrom() during debugging:
Code:
BOOL CRuntimeClass::IsDerivedFrom(const CRuntimeClass* pBaseClass) const
{
ASSERT(this != NULL);
ASSERT(AfxIsValidAddress(this, sizeof(CRuntimeClass), FALSE));
ASSERT(pBaseClass != NULL);
ASSERT(AfxIsValidAddress(pBaseClass, sizeof(CRuntimeClass), FALSE));
// simple SI case
const CRuntimeClass* pClassThis = this;
while (pClassThis != NULL)
{
if (pClassThis == pBaseClass)
return TRUE;
#ifdef _AFXDLL
pClassThis = (*pClassThis->m_pfnGetBaseClass)();
#else
pClassThis = pClassThis->m_pBaseClass;
#endif
}
return FALSE; // walked to the top, no match
}
Where exactly (at what line) does the Debug assertion fail?
Victor Nijegorodov
-
April 29th, 2010, 02:11 PM
#6
Re: CSingleLock Instantiation gets a Debug Assert
Actually the 2nd assert in the constructor (IsKindOf()) is raised
Code:
CSingleLock::CSingleLock(CSyncObject* pObject, BOOL bInitialLock)
{
ASSERT(pObject != NULL);
ASSERT(pObject->IsKindOf(RUNTIME_CLASS(CSyncObject)));
m_pObject = pObject;
m_hObject = pObject->m_hObject;
m_bAcquired = FALSE;
if (bInitialLock)
Lock();
}
IsKindOf() itself calls up IsDerivedFrom() shown in my initial post.
Code:
BOOL CObject::IsKindOf(const CRuntimeClass* pClass) const
{
ASSERT(this != NULL);
// it better be in valid memory, at least for CObject size
ASSERT(AfxIsValidAddress(this, sizeof(CObject)));
// simple SI case
CRuntimeClass* pClassThis = GetRuntimeClass();
return pClassThis->IsDerivedFrom(pClass);
}
IsDerivedFrom() returns FALSE due to the reason mentioned and thus IsKindOf() also returns FALSE which raises the assertion.
-
April 29th, 2010, 02:14 PM
#7
Re: CSingleLock Instantiation gets a Debug Assert
Use the debugger to look at pObject in this line.
ASSERT(pObject->IsKindOf(RUNTIME_CLASS(CSyncObject)));
What does the debugger think it is?
-
April 29th, 2010, 02:29 PM
#8
Re: CSingleLock Instantiation gets a Debug Assert
pObject is of type CSemaphore and the member classCSyncObject is set to "CSyncObject".
-
April 29th, 2010, 02:46 PM
#9
Re: CSingleLock Instantiation gets a Debug Assert
Originally Posted by greve
pObject is of type CSemaphore and the member classCSyncObject is set to "CSyncObject".
You got that from the debugger and you're sure the ASSERT is coming from that line? If pObject is a CSyncObject, I don't see how ASSERT(pObject->IsKindOf(RUNTIME_CLASS(CSyncObject))); would fire.
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
|