CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 1999
    Location
    Darmstadt, FRG
    Posts
    87

    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?

  2. #2
    Join Date
    Aug 1999
    Location
    Darmstadt, FRG
    Posts
    87

    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?

  3. #3
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    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?

  4. #4
    Join Date
    Aug 1999
    Location
    Darmstadt, FRG
    Posts
    87

    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

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: CSingleLock Instantiation gets a Debug Assert

    Quote Originally Posted by greve View Post
    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

  6. #6
    Join Date
    Aug 1999
    Location
    Darmstadt, FRG
    Posts
    87

    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.

  7. #7
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    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?

  8. #8
    Join Date
    Aug 1999
    Location
    Darmstadt, FRG
    Posts
    87

    Re: CSingleLock Instantiation gets a Debug Assert

    pObject is of type CSemaphore and the member classCSyncObject is set to "CSyncObject".

  9. #9
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: CSingleLock Instantiation gets a Debug Assert

    Quote Originally Posted by greve View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured