ATLASSUME(m_bInitialized) assertion failing after porting to VS2008

There was a post on social.msdn.com explaining the situation, but the page is now gone. Here’s a copy from Google’s cache.

In classes like CComObject, the critical section is no longer initialized in the constructor. It has been moved to _AtlInitialConstruct. Most of the time, this change is transparent.

To make sure the critical section has been correctly initialized, the assert was added to the Lock() method.

If this assert is hit, it means that _AtlInitialConstruct has not been called.

Scenario 1
CCom*Object has been instantiated with new and _AtlInitialConstruct is not called after the new. If CreateInstance is used to instantiate the CComObject, CreateInstance automatically calls _AtlInitialConstruct.

Scenario 1 Resolution

Call _AtlInitialConstruct after the object has been instantiated with new. or
Create a CCom*Object instance using the static CreateInstance method.

Scenario 2
A class similar to CCom*Object (not part of ATL) has been written and used in the project that hits the ASSERT.

Scenario 2 Resolution

Modify CreateInstance method of the custom class to call _AtlInitialConsturct. See CComObject::CreateInstance implementation for the right place to make this call.

Thanks,
Sridhar Madhugiri
Software Engineer
Visual C++

  1. Check that you haven’t overridden InternalAddRef, and your implementation of InternalAddRef uses InterlockedIncrement(m_uRef) and not call Lock() directly

About this entry