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

Weird Runtime error

Started by Stormtrooper Jun 28, 2007 at 12:11 PM 9 replies 1.2k views
Original Post
Stormtrooper
Stormtrooper
I have no idea why I'm getting a runtime error here

void FocusHandler::requestFocus( Widget *widget )
{
	mToBeFocused = widget; // This line
}
Access violation writing location 0x00000004.

		mToBeFocused = widget;
00431063  mov         eax,dword ptr [this] 
00431066  mov         ecx,dword ptr [widget] 
00431069  mov         dword ptr [eax+4],ecx // Right Here
}
This is how I'm calling it:

void Gui::setTopWidget( Widget *widget )
{
	if( mTop == NULL )
		mTop = widget;
	mFocusHandler->requestFocus( widget );
	mFocusHandler->applyChanges();
}
Thanks, Ryan
rip-off
rip-off
mFocusHandler ( the "this" pointer in FocusHandler::requestFocus ) is probably NULL. Remeber to the compiler the line reads "this->mToBeFocused = widget;".

You've already got the debugger pointing at the bad line, now is the time to research how to get a backtrace and inspect various variable values.
Stormtrooper
Stormtrooper
Thanks, that fixed it. But I have another runtime error now:
KeyboardEvent InputManager::dequeueKeyboard(){	KeyboardEvent result = mKeyboardQueue.front(); // Right here	mKeyboardQueue.pop();	return result;}

The weird thing is, both result and mKeyboardQueue have values according to the debugger.
	KeyboardEvent result = mKeyboardQueue.front();00416A23  mov         ecx,dword ptr [this] 00416A26  add         ecx,14h 00416A29  call        std::queue<KeyboardEvent,std::deque<KeyboardEvent,std::allocator<KeyboardEvent> > >::front (41509Ah) 00416A2E  mov         ecx,dword ptr [eax] // THIS LINE00416A30  mov         dword ptr [result],ecx 
Antheus
Antheus
Quote:
KeyboardEvent result = mKeyboardQueue.front();


If mKeyboardQueue is empty, the result of front() will be undefined. MVS will raise an exception with secure iterators. I don't know what happens without them.

Quote:
When compiling with _SECURE_SCL 1, a runtime error will occur if you attempt to access an element in an empty list. See Checked Iterators for more information.
Stormtrooper
Stormtrooper
The thing is...I call if the list is empty before...
while( mInputManager->isKeyQueueEmpty() == false ){	KeyboardEvent keyEvent = mInputManager->dequeueKeyboard();    ...bool InputManager::isKeyQueueEmpty(){	return mKeyboardQueue.empty();}
Stormtrooper
Stormtrooper
Ok...well instead of running the exe externally and let windwos catch the exception, I ran it in debug mode in VC++ 05. It gives me an access violation when I check if the list is empty, instead of when I try to get the item at the front of the list:

0xC0000005: Access violation reading location 0xbaadf031.in <deque>:bool empty() const{	// test if sequence is empty	return (_Mysize == 0); // THIS LINE IS ERROR}		return (_Mysize == 0);00417243  mov         eax,dword ptr [this] 00417246  xor         ecx,ecx 00417248  cmp         dword ptr [eax+10h],0 // HERE
cshowe
cshowe
Well in the assembly eax appears to be 0 or sufficiently small that you're access violating. This suggests that the this pointer is null which means that the object you're calling empty on is invalid. Just a guess
Dave Hunt
Dave Hunt
Are you sure mInputManager has been allocated?
Stormtrooper
Stormtrooper
Aha! THANK YOU!

void Gui::setInputManager( InputManager *inputManager ){	//if( mInputManager == NULL )		mInputManager = inputManager;}


The if statement was preventing the mInputManager from being set. But even if I make mInputManager null in the constructor, it still didn't fix it. So I'll have to leave it commented out for now. Thanks again!

Topic Locked

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

Sign in to reply to this topic.