Jump to content
  • Advertisement
Sign in to follow this  
supagu

memory overrun/underrun assigning pointer

This topic is 4650 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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 :-/

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!