Archived

This topic is now archived and is closed to further replies.

Gomac

Anyone know why this object crashes the program?

Recommended Posts

I am trying to create a simple terrain generation object, but whenever I try to create an instance of this object the program crashes and I get one of the standard "openGlterrain.exe has encountered a problem and needs to close. We are sorry for the inconvenience." message with debug, send error report and don't send messages on. the error MSVC++ gives when I press debug is:
quote:
Loaded symbols for 'C:\Program Files\Microsoft Visual Studio\MyProjects\openGlterrain\Debug\openGlterrain.exe' Loaded 'C:\WINDOWS\system32\ntdll.dll', no matching symbolic information found. Loaded 'C:\WINDOWS\system32\kernel32.dll', no matching symbolic information found. Loaded 'C:\WINDOWS\system32\opengl32.dll', no matching symbolic information found. Loaded 'C:\WINDOWS\system32\msvcrt.dll', no matching symbolic information found. Loaded 'C:\WINDOWS\system32\advapi32.dll', no matching symbolic information found. Loaded 'C:\WINDOWS\system32\rpcrt4.dll', no matching symbolic information found. Loaded 'C:\WINDOWS\system32\gdi32.dll', no matching symbolic information found. Loaded 'C:\WINDOWS\system32\user32.dll', no matching symbolic information found. Loaded 'C:\WINDOWS\system32\glu32.dll', no matching symbolic information found. Loaded 'C:\WINDOWS\system32\ddraw.dll', no matching symbolic information found. Loaded 'C:\WINDOWS\system32\dciman32.dll', no matching symbolic information found. Loaded 'C:\WINDOWS\system32\uxtheme.dll', no matching symbolic information found. Loaded 'C:\WINDOWS\system32\msctf.dll', no matching symbolic information found. Loaded 'C:\WINDOWS\system32\SSSensor.dll', no matching symbolic information found. Loaded 'C:\WINDOWS\system32\nvoglnt.dll', no matching symbolic information found. Loaded 'C:\Program Files\AIM95\idlemon.dll', no matching symbolic information found. Loaded 'C:\WINDOWS\system32\version.dll', no matching symbolic information found. Loaded 'C:\WINDOWS\system32\shlwapi.dll', no matching symbolic information found. Loaded 'C:\WINDOWS\system32\apphelp.dll', no matching symbolic information found. The thread 0xAB0 has exited with code 0 (0x0). The thread 0x944 has exited with code -1073741571 (0xC00000FD). The program 'C:\Program Files\Microsoft Visual Studio\MyProjects\openGlterrain\Debug\openGlterrain.exe' has exited with code -1073741571 (0xC00000FD).
the code is: TerrainEngine.h
        
// TerrainEngine.h: interface for the CTerrainEngine class.

//

//////////////////////////////////////////////////////////////////////


#if !defined(AFX_TERRAINENGINE_H__49F559E3_8170_4F4D_9EF9_F7986F10AA19__INCLUDED_)
#define AFX_TERRAINENGINE_H__49F559E3_8170_4F4D_9EF9_F7986F10AA19__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


#include <windows.h>
#include <windowsx.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <stdio.h>
#include <stdlib.h>

#define MAPSIZE 1024

class CTerrainEngine  
{
public:
	CTerrainEngine(LPSTR strName, int stepSize);
	virtual ~CTerrainEngine();
	
	void renderIt();
	void setStepSize(int s) { m_nStepSize = s;}
	int getStepSize() const {return m_nStepSize;}

private:
	BYTE m_HeightMap[MAPSIZE*MAPSIZE];
	int m_nStepSize;

	bool LoadRawFile(LPSTR strName);
	int getHeight(int x, int z);	
};

#endif //!defined(AFX_TERRAINENGINE_H__49F559E3_8170_4F4D_9EF9_F7986F10AA19__INCLUDED_)

  
TerrainEngine.cpp
              
// TerrainEngine.cpp: implementation of the CTerrainEngine class.

//

//////////////////////////////////////////////////////////////////////


#include "TerrainEngine.h"

//////////////////////////////////////////////////////////////////////

// Construction/Destruction

//////////////////////////////////////////////////////////////////////


CTerrainEngine::CTerrainEngine(LPSTR strName, int stepSize)
{
	if(this->LoadRawFile(strName))
	{
		this->setStepSize(stepSize);
	}
	else
	{
		MessageBox(NULL, "Could not create Terrain Engine", "Error", MB_OK);
	}
}

CTerrainEngine::~CTerrainEngine()
{

}

bool CTerrainEngine::LoadRawFile(LPSTR strName)
{
	FILE *pFile = NULL;

	//open file

 	pFile = fopen(strName, "rb");

	//check to see if we found the file and could open it

	if(pFile == NULL)
	{
		MessageBox(NULL, "Can't open the heightmap!", "Error", MB_OK);
		return false;
	}

	//load .raw to heightmap array

	fread(this->m_HeightMap, 1, (MAPSIZE*MAPSIZE), pFile);

	//check read ok

	int result = ferror(pFile);

	//check if recieved error

	if(result)
	{
		MessageBox(NULL, "Can't get data!", "Error", MB_OK);
		//close file

		fclose(pFile);
		return false;
	}
	
	//close file

	fclose(pFile);
	return true;
}

void CTerrainEngine::renderIt()
{
	int x,y,z;			 //create some vars for readability

	float fColour = 0.0f; //colour of polygon


	if(!(this->m_HeightMap)) return; //check height data is valid


	glBegin( GL_QUADS );  //render Quads


		//walk arrays

		for(int cX=0; cX<MAPSIZE; cX+=this->getStepSize())
		{
			for(int cZ=0; cZ<MAPSIZE; cZ+=this->getStepSize())
			{
				//set vector colour to white

				glColor3f(1.0f, 1.0f, 1.0f);
				//get x y and z values for bottom left vertex

				x = cX;
				y = this->getHeight(cX, cZ);
				z = cZ;

				//send vertex to be rendered in openGL

				glVertex3i(x, y, z);

				//top left vertex

				z = cZ+this->getStepSize();
				y = this->getHeight(cX, z);

				//send vertex to be rendered in openGL

				glVertex3i(x, y, z);

				//top right vertex

				x = cX + this->getStepSize();
				z = cZ + this->getStepSize();
				y = this->getHeight(x,z);

				//send vertex to be rendered in openGL

				glVertex3i(x, y, z);

				//bottom right vertex

				x = cX + this->getStepSize();
				y = this->getHeight(x, cZ);
				z = cZ;

				//send vertex to be rendered in openGL

				glVertex3i(x, y, z);
			}
		}
	glEnd();
}

int CTerrainEngine::getHeight(int x, int z)
{
	//make sure x and z values are within array

	x = x%MAPSIZE;
	z = z%MAPSIZE;

	if(!(this->m_HeightMap)) return 0;//check heightmap is valid


	/*use equation index = (x + (y*arrayWidth)) to simulate array[x][y] 
	  from a single array*/

	return this->m_HeightMap[x + (z*MAPSIZE)];
}
         
I have linked in opengl32.lib, glu32.lib and glaux.lib When I don't create the object the window loads up fine. It also crashes when I blank out the constructor and call the object. Any ideas why it crashes? Thanks [edited by - Gomac on July 26, 1762 7:49:19 PM] [edited by - Gomac on July 26, 2002 8:03:38 PM]

Share this post


Link to post
Share on other sites
general debugging tips:

http://www.gamedev.net/community/forums/topic.asp?topic_id=98522
http://www.gamedev.net/community/forums/topic.asp?topic_id=98664
http://www.gamedev.net/community/forums/topic.asp?topic_id=100019


---
Come to #directxdev IRC channel on AfterNET

Share this post


Link to post
Share on other sites
try alocating the big heghtmap dynamically (with malloc or the like, can be done easily within constructor/destructor)

i think i had a simmilar problem a few weeks ago...


mfg Phreak
--
"Input... need input!" - Johnny Five, Short Circuit.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
For the record, your error indicates a stack overflow. The absence of the symbol tables is normal.

Remember that in your class here, you are streaming a megabyte of data (plus whatever other gunk the functions put into the stream). I suspect that the failure is occurring inside the C-style file streaming operations. Try single-stepping through.

I have no idea what the documented maximum file lengths for those file functions are, but a megabyte is pushing your luck.

Share this post


Link to post
Share on other sites