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

Annoying Memory Error

Started by mhays Apr 21, 2003 at 10:42 PM 2 replies 500+ views
Original Post
mhays
mhays
I keep getting an exception in this line: if (!HeapValidate(_crtheap, 0, NULL)) of the int __cdecl _heapchk (void) function. I''m using .net Professional. This is the code is causing the problems...
  
	FILE * f = fopen(FName,"rb");
	if(f == NULL)
		return;

	fread(&NumFrames, 1, sizeof(int), f);
	fread(&ArraySize, 1, sizeof(int), f);
	fread(&UVArraySize,1,sizeof(int), f);

	TVertices = new float[NumFrames];

	Vertices = new float*[NumFrames];
	Colors = new char*[NumFrames];

	WeapFront = new Vertex[NumFrames];
	WeapBack = new Vertex[NumFrames];

	fread(TVertices,sizeof(float),UVArraySize,f);
	
	for(int i=0;i<NumFrames;i++)
	{
		fread(&WeapFront[i],sizeof(Vertex),1,f);
		fread(&WeapBack[i],sizeof(Vertex),1,f);

		Vertices[i] = new float[ArraySize];
		Colors[i] = new char[ArraySize];

		fread(Vertices[i],ArraySize,sizeof(float),f);
		fread(Colors[i],ArraySize,sizeof(char),f);
	}

	fclose(f);
  
The error happens on the 27th iteration of the bottom loop, when new is called on the Vertices pointer. NumFrames is somewhere in the vicinity of 200, and ArraySize is around 10,000. The Vertices var is defined as float ** Vertices; I really can''t find what''s causing this error. Just hoping that a few more sets of eyes might help me out. I have service pack 2 for .net installed. Thanks Marcus
--------------------------------------------------"I have never let my schooling interfere with my education. " --- M.TwainMarcus Hayswww.phrenicgames.com
Sneftel
Sneftel
Your error may not be here. If you''re fucking up heap memory somewhere else (usually by overrunning an array) you can run into problems when you try to actually allocate that memory for something.


How appropriate. You fight like a cow.
mhays
mhays
Yeah, I figured the same thing. So I rearranged the code so that this is the only code that is before it in the program...


  
MSG msg; // Windows Message Structure

WNDCLASS wc; // Windows Class Structure Used To Set Up The Type Of Window

HWND hWnd; // Storage For Window Handle


wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = lpszAppName;

if(!RegisterClass(&wc))
{
MessageBox(0,"Failed To Register The Window Class.","Error",MB_OK|MB_ICONERROR);
return FALSE;
}



hWnd = CreateWindow(
lpszAppName,
lpszAppName,

WS_POPUP |
WS_CLIPCHILDREN |
WS_CLIPSIBLINGS,

0, 0,
ScreenWidth, ScreenHeight,

NULL,
NULL,
hInstance,
NULL);

if(!hWnd)
{
MessageBox(0,"Window Creation Error.","Error",MB_OK|MB_ICONERROR);
return FALSE;
}

DEVMODE dmScreenSettings ;
dmScreenSettings.dmPelsWidth = ScreenWidth;
dmScreenSettings.dmPelsHeight = ScreenHeight;
dmScreenSettings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
dmScreenSettings.dmSize = sizeof(DEVMODE);
ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN);

ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
SetFocus(hWnd);
wglMakeCurrent(hDC,hRC);


and I still get the same error. Pretty annoying....

Marcus

--------------------------------------------------"I have never let my schooling interfere with my education. " --- M.TwainMarcus Hayswww.phrenicgames.com
mhays
mhays
And what''s even stranger, is that if i step the thru the loop, with a break point inside the loop each time, the error never happens, but if i just step to after the loop, then it happens...

grrr.

M
--------------------------------------------------"I have never let my schooling interfere with my education. " --- M.TwainMarcus Hayswww.phrenicgames.com

Topic Locked

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

Sign in to reply to this topic.