mfc >> CSplitterWnd, CFormView and a debug assertion failure

by loquak » Sun, 25 Apr 2004 21:43:37 GMT

Hello group-

I'm using the following code to set up two views using CSplitterWnd, on the
left side is a normal CView object and on the right side a CFormView object
with a tab control in it.

if(!m_wndSplitter.CreateStatic(this, 1, 2)) return FALSE;

// CNormalView descends from CView

if(!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CNormalView), CSize(100,
100), pContext) return FALSE;

// CTabbedView descends from CFormView

if(!m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CTabbedView), CSize(100,
100), pContext)) return FALSE; <<--- DEBUG ASSERTION FAILURE

What causes this error? What I'm trying to do is simply put a tabbed control
on the right side of the window, if this isn't the right approach I'd like
to know it.

mfc >> CSplitterWnd, CFormView and a debug assertion failure

by Scott McPhillips [MVP] » Mon, 26 Apr 2004 00:57:32 GMT

You have not provided any information that could help diagnose the
problem. You need to look at the ASSERT statement that failed, and the
value of whatever variables were involved at that point, and the class
and function that contain the ASSERT. You can only do this if you
install the MFC source code from the CD.

Scott McPhillips [VC++ MVP]

mfc >> CSplitterWnd, CFormView and a debug assertion failure

by loquak » Mon, 26 Apr 2004 02:51:23 GMT

Thanks for the feedback, there was indeed an explanation for the error which
I had overlooked - the resource should have been set to child style!

Similar Threads

1. Debug Assertion Failure

2. using CFileException - "Debug Assertion Failure" raised

When I call "GetErrorMessage" on the CFileException object, as in the 
following snipet, I get a "Debug Assertion Failed!" error dialog:

Code snipet:
CString fileName = _T("C:\\someFile.xsd");
CFile XSDFile;
CFileException fileException;

    if ( !XSDFile.Open(fileName, CFile::modeRead, &fileException) )
		// Problem opening the file, determine error
		TCHAR errCause[1024];

		//TODO - Debug assertion raised on this line, why??
		fileException.GetErrorMessage(errCause, 1024);



I get an error on the following ASSERT:

	{ ASSERT(afxCurrentResourceHandle != NULL);
		return afxCurrentResourceHandle; }

Can anyone explain why? or how to resolve?
Error only occurs in Debug configuration, not in a Release configuration.

3. STL - Debug assertion failure, vector iterator not dereferencable

4. STL - Debug assertion failure, vector iterator not dereferenca

Thanks for the explanation Igor,

I tried the code you supplied and it worked but this brings up another 
question what does one return when the vector is empty E_FAIL?

As for the other problem, as it turns out the vector is empty on that 
statement. I am using recursion in this routine so I will need to track down 
the bug. It's odd that these routines both used to work before converting 
them to 2005. Microsoft must have improved the error trapping in their STL.

"Igor Tandetnik" wrote:

> John < XXXX@XXXXX.COM > wrote:
> > I recently converted a visual studio .net project to visual studio
> > 2005 project. After
> > the conversion I am now having runtime errors on a collection that is
> > composed of a vector of CComVariants.
> >
> > std::vector<CComVariant> m_vecResults;
> >
> > More specifically it  gives me a Debug assertion failure, vector
> > iterator not dereferencable in my get__NewEnum method on the Init
> > statement in the following
> > code;
> >
> > STDMETHODIMP get__NewEnum(IUnknown** ppUnk)
> > {
> >    typedef CComObject<CComEnum<IEnumVARIANT, &IID_IEnumVARIANT,
> >         VARIANT, _Copy<VARIANT> > > enumVariant;
> >    enumVariant* pEnum = new enumVariant;
> >    HRESULT hr = pEnum->Init(&*m_vecResults.begin(),
> >                               &*m_vecResults.end(),
> >                               0,
> >                               AtlFlagCopy );
> This code exhibits undefined behavior, and could only ever work by 
> accident. Specifically, *m_vecResults.end() is illegal - an end() 
> iterator is not dereferenceable. Try this:
> CComVariant* pStart = 0;
> CComVariant* pEnd = 0;
> if (!m_vecResults.empty()) {
>     pStart = &m_vecResults.front();
>     pEnd = pStart + m_vecResults.size();
> }
> pEnum->Init(pStart, pEnd, ...);
> > So I modified my code to the following the following to not use
> > begin/end and it
> > seemed to of fix the problem.
> >
> > STDMETHODIMP get__NewEnum(IUnknown** ppUnk)
> > {
> >       typedef CComObject<CComEnum<IEnumVARIANT, &IID_IEnumVARIANT,
> >          VARIANT, _Copy<VARIANT> > > enumVariant;
> >      size_t nSize = m_vecResults.size();
> >      enumVariant* pEnum = new enumVariant;
> >      HRESULT hr = pEnum->Init(&m_vecResults[0],
> > &m_vecResults[nSize-1], NULL,
> >         AtlFlagCopy);
> This a) doesn't work when the vector is empty, and b) always leaves the 
> last element out.
> > Now I have another piece of code that uses a priority queue;
> >
> > typedef priority_queue< CRfItem, vector< CRfItem >, CRfItem::greater >
> > RfQueue;
> > RfQueue m_QueueAllPoints;
> >
> > I am experiencing the same error again in the following code segment
> > on the top()
> > statment;
> >
> > RfQueue::value_type temp =;
> Is the queue empty at this point, by any chance?
> -- 
> With best wishes,
>     Igor Tandetnik
> With sufficient thrust, pigs fly just fine. However, this is not 
> necessarily a good idea. It is hard to be sure where they are going to 
> land, and it could be dangerous sitting under them as they fly 
> overhead. -- RFC 1925

5. COleObjectFactory::RegisterAll() causes Assertion Failure in Debug mode

6. Debug Assertion Failure


Whenever I delete an object of a class derived from CObject in debug mode, I
get the following

Debug Assertion Failed!

Program: [Application Path]
File: dbgheap.c
Line : 1084

Expression: phead->nBlockUse = = nBlockUse

Can anyone tell how to rectify this problem.
Any help would be apprecited.


7. Debug Assertion failure....

8. Assertion Failure in debug mode only.


I am pretty new to C++ and even newer to windows programming.
Nonetheless, I have written a fairly large application (exe) that has
been working fine up until today.  The application is a single dialog
with a property sheet and several property pages.  I am trying to use
"GetOpenFileName" as documented in MSDN on one of the property pages,
but get an access violation in "afxwin1.inl" line 24 when the
application itself first starts up.

>>This is the assertion in afxwin1.inl:
>>line 23:        _AFXWIN_INLINE HINSTANCE AFXAPI AfxGetResourceHandle()
>>line 24:	{ ASSERT(afxCurrentResourceHandle != NULL);
>>line 25:	return afxCurrentResourceHandle; }

The error only occurs when I'm running my MFC Debug build
configuration.  The release configuration "seems" to work fine (so
far).  I've juggled the few lines of newly added code around quite a
bit to no avail.  Here's what I have at the moment:

void TAB_DEVICE5::OnBnClickedProgramFirmware()
	OPENFILENAME ofn;			// common dialog box structure
	char szFile[260] = "";                        // buffer for file name
	//HANDLE hf;				       // file handle

	ZeroMemory( &ofn, sizeof( ofn ) );
	ofn.lStructSize = sizeof( ofn);
	ofn.lpstrFile = szFile;
	ofn.hwndOwner = NULL;
	ofn.nMaxFile = sizeof( szFile );
	ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";
	ofn.nFilterIndex = 1;
	ofn.lpstrFileTitle = NULL;
	ofn.nMaxFileTitle = 0;
	ofn.lpstrInitialDir = NULL;

	GetOpenFileName( &ofn );

If I comment out the single line "GetOpenFileName( &ofn );", the
assertion failure goes away.  Any ideas?  This is my first time ever
posting in a newsgroup (hope I have the right one).  This project is
being compiled in VS .NET 2005.  I started it in VS 6 and moved it into
.NET about a month ago. 

Thanks in advance for reading!