Alright, after I've fixed these bugs I'll work on my ini file reader and make it a little claner. Thanks for your advice on that.
However, the ini file reader is not the key problem here. I can comment out the ini file reader and just use temporary values in the code [that's what I'm currently doing, although when I do uncomment it, nothing has changed). The reason I posted the ini file problem in here with the rest of it is:
1) The errors I'm encountering in the ini file mimic the problems I've had elsewhere
2) The ini file happens incredibly early in the code, including before windows and direct x are initialised
But the real problem is my heightmap class, and why it's erasing itself. Although I think that if I fix that, the ini file would probably work again...I'm pretty surethat it's the same problem, ESPECIALLY considering that the ini file reader has worked for me in another project.
Originally Posted by
vart
You can also use some very strict static code checkers (for exsample buffer overruns can be found by them) - like PCLint - it brings a lot more warnings then the regular VC compiler.
At least set warning level at maximum in your compiler and don't just ignore them
I looked at PCLint, but it costs money, I hate to sound like a cheapo but are there any free versions/programs like that at this point?
I set my compiler warning to max, and cleared all of the warning that showed up (except 4 - which are for variables passed in to functions that aren't used. Three were from WinMain and one is from a function where I just haven't used the variable yet, although that function has not yet been called before things are screwing up).
I tried running it after that, with the ini file reader uncommented, and I found that the count variable was behaving differently. Quite simply...C++ didn't recognise it, when I ran my mouse over it, no value popped up, and when I put it in the watch window, it said that 'symbol 'count' cannot be found'. It seems that the variable is being completely ignored now.
Originally Posted by
Salem
Please tell me you're not using threads as well.
XD That would be frightening
Originally Posted by
Salem
3. If you end up with main() and iniFileReader::loadFile(), and it still crashes, then post the WHOLE thing.
That's *essentially what I have right now...below is the code in my main file:
Code:
#include "game.h"
//globals
game *Glitch = new game();
bool Render(float timeDelta)
{
Glitch->beginRender();
//RenderCode Here
Glitch->endRender();
return true;
}//bool Render(float timeDelta)
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd)
{
//initialisation stuff
if(Glitch->init(hInstance))
{
Glitch->mainLoop(Render);
}//if(Glitch->init(hInstance))
else
{
MessageBoxA(NULL,
"Error initialising Glitch.",
"Glitch", 0);
}//else
//cleanup stuff
delete(Glitch);
return 0;
}
And here's the code in Glitch->init(hInstance):
Code:
bool game::init(HINSTANCE hInstance)
{
iniFileReader i;
i.loadFile("Glitch.ini");
bool fullscreen = false;
char* name = "Glitch";
DWORD style = WS_VISIBLE;
if(fullscreen)
style |= WS_POPUP | WS_EX_TOPMOST;
int width = 640; int height = 480;
D3DDEVTYPE devicetype = D3DDEVTYPE_HAL;
WNDCLASSEX wcex;
ZeroMemory(&wcex, sizeof(wcex));
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC) WndProc;
wcex.hInstance= hInstance;
wcex.hCursor= LoadCursor(NULL, IDC_ARROW);
wcex.lpszClassName= name;
HWND hWnd;
hWnd = CreateWindow(name, name, style, CW_USEDEFAULT, 0, width, height, NULL,NULL, hInstance, NULL);
if(!hWnd)
{
return false;
}//if(!hWnd)
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
HRESULT hr;
LPDIRECT3D9 d3d9 = NULL;
if(NULL == (d3d9= Direct3DCreate9(D3D_SDK_VERSION)))
{
return false;
}//if(NULL == d3d9)
D3DCAPS9 caps;
d3d9->GetDeviceCaps(D3DADAPTER_DEFAULT, devicetype, &caps);
int vp = 0;
if(caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT)
{
vp = D3DCREATE_HARDWARE_VERTEXPROCESSING
}//if(caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT)
else
{
vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
}//else
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.BackBufferWidth = width;
d3dpp.BackBufferHeight = height;
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hWnd;
d3dpp.Windowed = !fullscreen;
d3dpp.EnableAutoDepthStencil = true;
d3dpp.AutoDepthStencilFormat = D3DFMT_D32;
d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
hr = d3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, vp, &d3dpp, &device);
if(hr != D3D_OK)
{
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
hr = d3d9->CreateDevice(D3DADAPTER_DEFAULT, devicetype, hWnd, vp, &d3dpp, &device);
if(hr != D3D_OK)
{
d3d9->Release();
return false;
}//if(FAILED(hr))
}//if(FAILED(hr))
d3d9->Release();
h = new heightMap();
h->initHeightmap(device, "coastMountain64.raw", 64, 64, 10, 0.5);
rendering = false;
BGColor = D3DCOLOR_XRGB(0, 0, 0);
D3DXMATRIX proj;
D3DXMatrixPerspectiveFovLH(&proj, D3DX_PI / 2, (float)width / (float)height, 0, 1000);
device->SetTransform(D3DTS_PROJECTION, &proj);
//sets the camera
D3DXVECTOR3 pos(6, 0, 0);
D3DXVECTOR3 target(0, 0, 0);
D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
D3DXMATRIX result;
D3DXMatrixLookAtLH(&result, &pos, &target, &up);
device->SetTransform(D3DTS_VIEW, &result);
return true;
}//game::init(HINSTANCE hInstance)
And here's the heightMap::initheightMap function:
Code:
bool heightMap::initHeightmap(IDirect3DDevice9 *nDevice, char *fname, int nNumVertsPerRow,
int nNumVertsPerCol, int nCellSpacing, float nHeightScale)
{
device = nDevice;
numVertsPerRow = nNumVertsPerRow;
numVertsPerCol = nNumVertsPerCol;
cellSpacing = nCellSpacing;
heightScale = nHeightScale;
numCellsPerRow = numVertsPerRow - 1;
numCellsPerCol = numVertsPerCol - 1;
width = numCellsPerRow * cellSpacing;
depth = numCellsPerRow * cellSpacing;
numVertices = numVertsPerRow * numVertsPerCol;
numTriangles = numCellsPerRow * numCellsPerCol * 2;
heightScale = nHeightScale;
if(!readRawFile(fname))
{
return false;
}//if(!readRawFile(fname))
return true;
}//bool heightMap::init(IDirect3DDevice9 *nDevice, char *fname, int nNumVertsPerRow, ...
bool heightMap::readRawFile(char *fname)
{
std::vector<BYTE> in(numVertices);
std::ifstream inFile(fname, std::ios_base::binary);
if(inFile == NULL) return false;
inFile.read((char*)&in[0], in.size());
inFile.close();
// map.resize(numVertices);
for(unsigned int i = 0; i < in.size(); i++)
{
// map[i] = in[i];
}
return true;
}
(NOTE: in the readRawFile function, the commented out variable 'map' is a vector that I commented out thinking that it may be the cause fo the problem, which it wasn't.)