Skip to main content
GameDev.net gamedev.net
🔒 Locked

"Debug Assertion Failed ! ", Please help

Started by cm_tanko Aug 13, 2010 at 8:29 PM 6 replies 3.1k views
Original Post
cm_tanko
cm_tanko
I have developed a very simple program with sprites and back buffer feature. my problem is

"the game runs perfectly fine with no errors and warnings. But when the window is closed, there is this message "

________________________________________________________________
Debug Assertion Failed!

Program:...\myGame\Debug\myGame.exe
File: f:\Program files\microsoft visual studio 9.0\vc\include\vector
Line: 138

Expression: ("this->_Has_container()",0)

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.

(Press Retry to debug the application)
_________________________________________________________________

I dont know from where this error is generated. obviously the problem cant be with the vector header file (as it is build in)..


cmTanko
empirical2
empirical2
Did you press retry to debug the application and step back to the last function that is within your project?

On my copy of VC9 line 138 is for an operator -- do you use such an operator in your program?

Errors that occur when a program is quitting is often because you have freed an object and then try to access it, perhaps in response to a window message.
telaryus
telaryus
Sounds like on clean up you went out of bounds on the vector. Best way to find it is to retry on the message window and then walk up the call stack till you hit your code and then determine from there what the problem might be.
"My word is my bond and here I stand."
iMalc
iMalc
This is the code containing line 138 from vector in VS2008:
	_Myt& operator--()		{	// predecrement		_SCL_SECURE_VALIDATE(this->_Has_container());		_SCL_SECURE_VALIDATE_RANGE(_Myptr > ((_Myvec *)(this->_Getmycont()))->_Myfirst); #if _HAS_ITERATOR_DEBUGGING		if (this->_Mycont == 0			|| _Myptr == ((_Myvec *)this->_Mycont)->_Myfirst)			_DEBUG_ERROR("vector iterator not decrementable"); #endif /* _HAS_ITERATOR_DEBUGGING */		--_Myptr;		return (*this);		}

So obviously the problem is happening when predecrementing an iterator. It appears that when the iterator is predecremented, it isn't actually pointing to a container at all. I.e. you could produce this bug by doing:
std::vector<int>::iterator it;--it;

When the problem happens, click retry and bring up the callstack window. Broswe the function heirarchy in there to see what your code is doing and you should see the problem.
Denzin
Denzin
More than likely it is in your cleanup code, possibly because something may be called twice. Check your vector cleanup.
cm_tanko
cm_tanko
I have been trying to figure it out and seems my brain is going to be out....
When i Click Retry Button , it will point me to two functions
1> In Vector header file
____________________________________________________
_Myt& operator--()
{ // predecrement
_SCL_SECURE_VALIDATE(this->_Has_container());
_SCL_SECURE_VALIDATE_RANGE(_Myptr > ((_Myvec *)(this->_Getmycont()))->_Myfirst);

#if _HAS_ITERATOR_DEBUGGING
if (this->_Mycont == 0
|| _Myptr == ((_Myvec *)this->_Mycont)->_Myfirst)
_DEBUG_ERROR("vector iterator not decrementable");
#endif /* _HAS_ITERATOR_DEBUGGING */
__________________________________________________________

2> In dbgHook.c
_______________________________________________________
__declspec(noinline)
void __cdecl _CRT_DEBUGGER_HOOK(int _Reserved)
{
/* assign 0 to _debugger_hook_dummy so that the function is not folded in retail */
(_Reserved);
_debugger_hook_dummy = 0;
}
____________________________________________________________

.
.
.
.
I have then being removing all my functions to check in which function the error occurs,

Error occurs when I call the sprite class
eg.

// Create the ball sprites
RECT rcBounds = { 0, 0, 600, 400 };
Sprite* pSprite;

pSprite = new Sprite(_pBallBitmap, rcBounds, BA_BOUNCE);
pSprite->SetVelocity(5, 3);
_pGame->AddSprite(pSprite); //this will cause the error

where,
________________________________________________________________________
void GameEngine::AddSprite(Sprite* pSprite)
{
// Add a sprite to the sprite vector
if (pSprite != NULL)
{
// See if there are sprites already in the sprite vector
if (m_vSprites.size() > 0)
{
// Find a spot in the sprite vector to insert the sprite by its z-order
vector::iterator siSprite;
for (siSprite = m_vSprites.begin(); siSprite != m_vSprites.end(); siSprite++)
if (pSprite->GetZOrder() < (*siSprite)->GetZOrder())
{
// Insert the sprite into the sprite vector
m_vSprites.insert(siSprite, pSprite);
return;
}
}

// The sprite's z-order is highest, so add it to the end of the vector
m_vSprites.push_back(pSprite);
}
}
___________________________________________________________________________


maybe it can help you figure out if somethings wrong in the code....

I have been trying to learn but stocked in middle of the way .




thanks,
taz0010
taz0010
When the error occurs, click the call stack window to go up to the exact point where a line you wrote fails. You can inspect the contents of all variables, and all containers, and shouldn't have any trouble seeing what's wrong.
iMalc
iMalc
Quote:
Original post by cm_tanko
I have been trying to figure it out and seems my brain is going to be out....
When i Click Retry Button , it will point me to two functions
1> In Vector header file
You should be able to see more than that. If the callstack below that is just showing the module name and some hexadecimal address then perhaps the symbols are not loading for debugging. You may want to post a screenshot of the callstack window so we can see why you are having difficulty.

If it's working correctly then you really should be able to see exactly where the problem is from double-clicking your functions in the callstack window.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.