Skip to main content
gamedev.net
🔒 Locked

memory overrun/underrun assigning pointer

Started by supagu Sep 23, 2005 at 7:39 PM 1 replies 600+ views
Original Post
supagu
supagu
seems when i assign a pointer, im getting the last variable in one class overwritten. so i have the following code (note, nop's just for debugging purposes):

void OGLDevice::SetActiveWindow(Win32Window* wnd)
{
	__asm nop
	activeWindow = wnd;
	__asm nop
	ResetDevice(activeWindow->GetWidth(), activeWindow->GetHeight());
}
equates to this in assembly with vc2005 beta 2:

	__asm nop
00408073  nop              
	activeWindow = wnd;
00408074  mov         eax,dword ptr [this] 
00408077  mov         ecx,dword ptr [wnd] 
0040807A  mov         dword ptr [eax],ecx 
	__asm nop
0040807C  nop
now: this = 0x0012fcd5 wnd = 0x0012fcbc &(wnd->height) = 0x0012fcd4 obviously wnd->height is the last variable in my wnd class with the this class comming right after it. Seems when i do my pointer assignment, it writes data to both this->activeWindow (which is the first variable in the this class), and wnd->height. Both end up with an incorrect value how ever. If i take some variables out of my wnd class this does not occur. I assume this is due to memory alignment or padding?
JohnBolton
JohnBolton
this = 0x0012fcd5 is suspicious. A class is usually aligned according to the size of its largest member. The value of this would normally be 0x.......0, 0x.......4, 0x.......8, or 0x.......C, not 0x.......5
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
supagu
supagu
okay seems the problem is when i allocate them on the stack. If i create them on the heap using new, then things work out correctly.

Strange :-/

Topic Locked

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

Sign in to reply to this topic.