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

DrawText problem

Started by HarrisonPloeg Feb 20, 2007 at 1:19 AM 12 replies 1.7k views
Original Post
HarrisonPloeg
HarrisonPloeg
When I run a program using the DrawText function the program crashes, example code: gd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0); gd3dDevice->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); gd3dDevice->BeginScene(); gd3dDevice->SetFVF(CUSTOMFVF); D3DXMATRIX matView; D3DXMATRIX matTranslate; D3DXMATRIX matScale; D3DXMATRIX matRotateZ; D3DXMatrixLookAtLH(&matView, &D3DXVECTOR3 (x, y, z), &D3DXVECTOR3 (x + 20.0f, y, 0.0f), &D3DXVECTOR3 (0.0f, 0.0f, -1.0f)); gd3dDevice->SetTransform(D3DTS_VIEW, &matView); D3DXMATRIX matProjection; D3DXMatrixPerspectiveFovLH(&matProjection, D3DXToRadian(45), SCREEN_WIDTH / SCREEN_HEIGHT, 1.0f, 8192.0f); gd3dDevice->SetTransform(D3DTS_PROJECTION, &matProjection); RECT R = {5, 5, 0, 0}; mFont->DrawText(NULL, _T("Text"), -1, &R, DT_NOCLIP, D3DCOLOR_XRGB(0,0,0)); gd3dDevice->EndScene(); gd3dDevice->Present(NULL, NULL, NULL, NULL); The font: ID3DXFont* mFont; D3DXFONT_DESC fontDesc; fontDesc.Height = 18; fontDesc.Width = 0; fontDesc.Weight = 0; fontDesc.MipLevels = 1; fontDesc.Italic = false; fontDesc.CharSet = DEFAULT_CHARSET; fontDesc.OutputPrecision = OUT_DEFAULT_PRECIS; fontDesc.Quality = DEFAULT_QUALITY; fontDesc.PitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; _tcscpy(fontDesc.FaceName, _T("Times New Roman")); D3DXCreateFontIndirect(gd3dDevice, &fontDesc, &mFont); If I take out DrawText the program runs fine. Have I missed something? [Edited by - HarrisonPloeg on February 20, 2007 1:38:51 AM]
Sc4Freak
Sc4Freak
You don't seem to be checking any of the return values. Always do error checking, in Direct3D you can do this by checking the HRESULT returned by functions (or using the FAILED() macro).

Once you do this, it should give you more of an idea of what's causing the problem.
DesignerX
DesignerX
You might want to change you rectangle definition since it is incorrect.
It needs to be :

RECT R = {0, 0, 5, 5};

I don't know if thats what causing the crashes but it will prevent another forthcoming bug.

Also , r u sure the _T macro adds the terminating character to the string ? try replacing -1 with 4.
There is nothing that can't be solved. Just people that can't solve it. :)
HarrisonPloeg
HarrisonPloeg
Why does it fail every time I run the program?
I can't use the FAILED() macro because the program has stopped by the time I can check if it's failed.
The book "Introduction to 3D Game Programming with DirectX 9.0c: A Shader Approach", uses similar code to what I'm using, that example program works.
DesignerX
DesignerX
Did you try what I suggested above ? (changing -1 with 4 and redefining your rectangle)
There is nothing that can't be solved. Just people that can't solve it. :)
Evil Steve
Evil Steve
In what way does it crash? Do you get an access violation? Does it just quit? Does your computer BSOD or reboot?

It's most likely to be an access violation reading 0x00000000, which means a null pointer. And since it crashes before the FAILED macro kicks in, it's a pointer bug, not a D3D bug. So, your mFont pointer is null or unset. Where do you set it? Do you check the return value from D3DXCreateFont()?
DesignerX
DesignerX
Excuse me for asking but you did initialized mFont before using it ?

Cause if the code is ordered is as you posted than the problem is quite obvious.
There is nothing that can't be solved. Just people that can't solve it. :)
HarrisonPloeg
HarrisonPloeg
The exception information says the error code is 0xc0000005 the flag is 0x00000000.
It just asks me if I want to send an error report.

It says that End and Begin are not members of ID3DXFont.
mFont is initialized before it is used.

[Edited by - HarrisonPloeg on February 21, 2007 2:04:11 AM]
DesignerX
DesignerX
I you don't mind revealing your code I'll be happy to debug it on my computer cause its hard to figure it out like this.
There is nothing that can't be solved. Just people that can't solve it. :)
HarrisonPloeg
HarrisonPloeg
#include <d3d9.h>#include <dinput.h>#include <d3dx9.h>#include <string>#include <tchar.h>#include <windows.h>#include <windowsx.h>#include <string>#include <fstream>using namespace std;float x = -32.0f;float y = 0.0f;float z = -80.0f;float floorHeight = 0.5f;int checkFrame = 0; //To stop some keys being checked each framebool doCheckFrame = false;int objectPlacementMode = 0; // 0=walls 1=floors 2=stairs 3=windows 4=doors |use to change type of object being placed downint maxObjects = 5; // if objectPlacementMode exceeds this number go back to zeroint maxredofloor = 0;int maxredowall = 0;int maxredostairs = 0;int maxredowindows = 0;int maxredodoors = 0;float mousePositionX = 0;float mousePositionY = 0;int wallBeingChecked = 0;bool checkFailed = false;int floorBeingChecked = 0;int stairsBeingChecked = 0;int windowBeingChecked = 0;int doorBeingChecked = 0;bool XaxisAligned = false;int rotate = 0;#define SCREEN_WIDTH  1024#define SCREEN_HEIGHT 768void initD3D(HWND hWnd);void render_frame(void);void cleanD3D(void);void loadBuilding();void saveBuilding();void init_graphics(void);    // 3D declarationsvoid init_light(void);LPDIRECT3DVERTEXBUFFER9 t_buffer = NULL;    // the pointer to the vertex bufferLPDIRECT3DSURFACE9 z_buffer = NULL;    // the pointer to the z-bufferLPD3DXMESH meshWall;LPD3DXMESH meshFloor;LPD3DXMESH meshStair;LPD3DXMESH meshWindow1;LPD3DXMESH meshWindow2;LPD3DXMESH meshDoor;LPDIRECT3DTEXTURE9 texGround;LPDIRECT3DTEXTURE9 texWall;LPDIRECT3DTEXTURE9 texStairs;LPDIRECT3DTEXTURE9 texFloor;struct CUSTOMVERTEX {FLOAT X, Y, Z; DWORD COLOR; FLOAT u, v;};#define CUSTOMFVF (D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE2(1))class wallClass{public:	float positionX;	float positionY;	float positionZ;	bool Xaxis;};class floorClass{public:	float positionX;	float positionY;	float positionZ;};class stairClass{public:	float positionX;	float positionY;	float positionZ;    int Xaxis;};class windowClass{public:	float positionX;	float positionY;	float positionZ;	bool Xaxis;};class doorClass{public:	float positionX;	float positionY;	float positionZ;	bool Xaxis;};int numberFloors = 0;int numberWalls = 0;int numberStairs = 0;int numberWindows = 0;int numberDoors = 0;int wallBeingDrawn = 0;int floorBeingDrawn = 0;int stairBeingDrawn = 0;int windowBeingDrawn = 0;int doorBeingDrawn = 0;floorClass floors[262144];wallClass wall[16392];stairClass stairs[2048];windowClass windows[2048];doorClass door[2048];DWORD starting_point;ID3DXFont* mFont;	 HWND hWnd;LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);// include the Direct3D Library file#pragma comment (lib, "d3d9.lib")#pragma comment (lib, "d3dx9.lib")#pragma comment (lib, "dinput.lib")#pragma comment (lib, "dinput8.lib")#pragma comment (lib, "dxguid.lib")LPDIRECTINPUT8 din;    // the pointer to our DirectInput interfaceLPDIRECTINPUTDEVICE8 dinkeyboard;    // the pointer to the keyboard deviceLPDIRECTINPUTDEVICE8 dinmouse;    // the pointer to the mouse device// function prototypesvoid initDInput(HINSTANCE hInstance, HWND hWnd);    // sets up and initializes DirectInputvoid detect_keys(void);    // gets the current keys being pressedvoid cleanDInput(void);    // closes DirectInput and releases memoryvoid detect_mousepos(void);    // gets the mouse movement and updates the static variablesIDirect3D9* d3d;IDirect3DDevice9* gd3dDevice;	static BYTE keystate[256];void detect_keys(void){    dinkeyboard->Acquire();    // get access if we don't have it already    dinkeyboard->GetDeviceState(256, (LPVOID)keystate);    // fill keystate with values	checkFrame += 1;	if(checkFrame >= 12)	{		doCheckFrame = false;		checkFrame = 0;	};	// check the 'escape' key        if(keystate[DIK_ESCAPE] & 0x80)		{		  if(keystate[DIK_Y] & 0x80)          PostMessage(hWnd, WM_DESTROY, 0, 0);	    };		if(keystate[DIK_W] & 0x80)		{			x += 1.0;			mousePositionX += 1.0f;		};		if(keystate[DIK_S] & 0x80)		{			x -= 1.0;			mousePositionX -= 1.0f;		};		if(keystate[DIK_A] & 0x80)		{			y += 1.0;			mousePositionY += 1.0f;		};		if(keystate[DIK_D] & 0x80)		{			y -= 1.0;			mousePositionY -= 1.0f;		};		if(keystate[DIK_1] & 0x80)			floorHeight = 0.5;		if(keystate[DIK_2] & 0x80)			floorHeight = -8.5;		if(keystate[DIK_3] & 0x80)			floorHeight = -16.5;		if(keystate[DIK_4] & 0x80)			floorHeight = -24.5;		if(keystate[DIK_5] & 0x80)			floorHeight = -32.5;		if(keystate[DIK_6] & 0x80)			floorHeight = -40.5;		if(keystate[DIK_7] & 0x80)			floorHeight = -48.5;		if(keystate[DIK_8] & 0x80)			floorHeight = -56.5;		if(keystate[DIK_9] & 0x80)			floorHeight = -64.5;		if(keystate[DIK_0] & 0x80)			floorHeight = - 72.5;		if(checkFrame == 0 || doCheckFrame == false)		{			if(keystate[DIK_P] & 0x80)			{				objectPlacementMode += 1;				if(objectPlacementMode >= maxObjects)				{					objectPlacementMode = 0;				};				doCheckFrame = true;			};		};		if(checkFrame == 0 || doCheckFrame == false)		{			if(keystate[DIK_F1] & 0x80)			{				z -= 8.0f;				floorHeight -= 8.0f;			};			if(keystate[DIK_F2] & 0x80)			{				z += 8.0f;				floorHeight += 8.0f;				if(z >= 0.5)					z = 0.5;			};		};		if(keystate[DIK_O] & 0x80)			z = -80.0f;		if(x >= 64.5f)			x = 64.5f;		if(x <= -64.5f)			x = -64.5f;		if(y >= 64.5f)			y = 64.5f;		if(y <= -64.5f)			y = -64.5f;		if(z <= -8192.0f)			z = -8192.0f;		if(floorHeight <= -8184.0f)			floorHeight += 8.0f;		if(floorHeight >= 0.5)			floorHeight = 0.5;		if(checkFrame == 0 || doCheckFrame == false || checkFrame == 5 || checkFrame == 10 || checkFrame == 11 || checkFrame == 8 || checkFrame == 3   )		{			if(keystate[DIK_LCONTROL] & 0x80 && keystate[DIK_Y] & 0x80)				numberWalls -= 1;			if(keystate[DIK_LCONTROL] & 0x80 && keystate[DIK_U] & 0x80)				numberFloors -= 1;			if(keystate[DIK_LCONTROL] & 0x80 && keystate[DIK_I] & 0x80)				numberStairs -= 1;			if(keystate[DIK_LCONTROL] & 0x80 && keystate[DIK_T] & 0x80)				numberWindows -= 1;			if(keystate[DIK_LCONTROL] & 0x80 && keystate[DIK_R] & 0x80)				numberDoors -= 1;			doCheckFrame = true;		};				if(checkFrame == 0 || doCheckFrame == false || checkFrame == 5 || checkFrame == 10 || checkFrame == 11 || checkFrame == 8 || checkFrame == 3   )		{			if(keystate[DIK_LALT] & 0x80 && keystate[DIK_Y] & 0x80)				if(numberWalls + 1 <= maxredowall)					numberWalls += 1;			if(keystate[DIK_LALT] & 0x80 && keystate[DIK_U] & 0x80)				if(numberFloors + 1 <= maxredofloor)					numberFloors += 1;			if(keystate[DIK_LALT] & 0x80 && keystate[DIK_I] & 0x80)				if(numberStairs + 1 <= maxredostairs)					numberStairs += 1;			if(keystate[DIK_LALT] & 0x80 && keystate[DIK_T] & 0x80)				if(numberWindows + 1 <= maxredowindows)					numberWindows += 1;			if(keystate[DIK_LALT] & 0x80 && keystate[DIK_R] & 0x80)				if(numberDoors + 1 <= maxredodoors)					numberDoors += 1;			doCheckFrame = true;		};		if(numberWalls <= 0)			numberWalls = 0;		if(numberFloors <= 0)			numberFloors = 0;		if(numberStairs <= 0)			numberStairs = 0;		if(numberWindows <= 0)			numberWindows = 0;		if(numberDoors <= 0)			numberDoors = 0;		if(keystate[DIK_F3] & 0x80)			{				z -= 8.0f;				floorHeight -= 8.0f;			};			if(keystate[DIK_F4] & 0x80)			{				z += 8.0f;				floorHeight += 8.0f;				if(z >= 0.5)					z = 0.5;			};    return;}int WINAPI WinMain(HINSTANCE hInstance,                   HINSTANCE hPrevInstance,                   LPSTR lpCmdLine,                   int nCmdShow){    WNDCLASSEX wc;    ZeroMemory(&wc, sizeof(WNDCLASSEX));    wc.cbSize = sizeof(WNDCLASSEX);    wc.style = CS_HREDRAW | CS_VREDRAW;    wc.lpfnWndProc = (WNDPROC)WindowProc;    wc.hInstance = hInstance;    wc.hCursor = LoadCursor(NULL, IDC_ARROW);    wc.lpszClassName = "D3DProgram";    RegisterClassEx(&wc);    hWnd = CreateWindowEx(NULL,                          "D3DProgram",                          "Program",                          WS_EX_TOPMOST | WS_POPUP,                           0, 0,                            SCREEN_WIDTH, SCREEN_HEIGHT,                            NULL,                          NULL,                          hInstance,                          NULL);    ShowWindow(hWnd, nCmdShow);D3DXFONT_DESC fontDesc;	fontDesc.Height          = 18;    fontDesc.Width           = 0;    fontDesc.Weight          = 0;    fontDesc.MipLevels       = 1;    fontDesc.Italic          = false;    fontDesc.CharSet         = DEFAULT_CHARSET;    fontDesc.OutputPrecision = OUT_DEFAULT_PRECIS;    fontDesc.Quality         = DEFAULT_QUALITY;    fontDesc.PitchAndFamily  = DEFAULT_PITCH | FF_DONTCARE;    _tcscpy(fontDesc.FaceName, _T("Times New Roman"));	D3DXCreateFontIndirect(gd3dDevice, &fontDesc, &mFont);	initD3D(hWnd);	initDInput(hInstance, hWnd);	MSG msg;    while(TRUE)    {        starting_point = GetTickCount();        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))        {            if (msg.message == WM_QUIT)                break;            TranslateMessage(&msg);            DispatchMessage(&msg);        }		detect_mousepos();		detect_keys();		init_graphics();        render_frame();               while ((GetTickCount() - starting_point) < 25);    }    // clean up DirectX and COM void    cleanD3D(); void	cleanDInput(); return msg.wParam;		}// this is the main message handler for the programLRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){    switch(message)    {        case WM_DESTROY:            {                PostQuitMessage(0);                return 0;            } break;    }    return DefWindowProc (hWnd, message, wParam, lParam);}void initD3D(HWND hWnd){    d3d = Direct3DCreate9(D3D_SDK_VERSION); // create the Direct3D interface    D3DPRESENT_PARAMETERS d3dpp; // create a struct to hold various device information    ZeroMemory(&d3dpp, sizeof(d3dpp));    // clear out the struct for use    d3dpp.Windowed = FALSE;    // program fullscreen, not windowed    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;    // discard old frames    d3dpp.hDeviceWindow = hWnd;    // set the window to be used by Direct3D    d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;    // set the back buffer format to 32-bit    d3dpp.BackBufferWidth = SCREEN_WIDTH;    // set the width of the buffer    d3dpp.BackBufferHeight = SCREEN_HEIGHT;    // set the height of the buffer	d3dpp.EnableAutoDepthStencil = TRUE;    // automatically run the z-buffer for us    d3dpp.AutoDepthStencilFormat = D3DFMT_D16;    // 16-bit pixel format for the z-buffer    d3d->CreateDevice(D3DADAPTER_DEFAULT,                      D3DDEVTYPE_HAL,                      hWnd,                      D3DCREATE_HARDWARE_VERTEXPROCESSING,                      &d3dpp,                      &gd3dDevice);	gd3dDevice->CreateDepthStencilSurface(SCREEN_WIDTH,    // the z-buffer width                                      SCREEN_HEIGHT,    // the z-buffer height                                      D3DFMT_D16,    // 16-bit pixel format                                      D3DMULTISAMPLE_NONE,    // no multisampling                                      0,    // no multisampling quality                                      TRUE,    // discard old buffer data                                      &z_buffer,    // the address of the buffer                                      NULL);    // reserved...we don't use this.	gd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE); // turn on the 3D lighting    gd3dDevice->SetRenderState(D3DRS_ZENABLE, TRUE);    // turn on the z-buffer	D3DXCreateBox(gd3dDevice, 1.0f, 8.0f, 8.0f, &meshWall, NULL);	D3DXCreateBox(gd3dDevice, 8.0f, 8.0f, 1.0f, &meshFloor, NULL);	D3DXCreateBox(gd3dDevice, 1.0f, 8.0f, 1.1f, &meshStair, NULL);	D3DXCreateBox(gd3dDevice, 1.0f, 3.0f, 8.0f, &meshWindow1, NULL);	D3DXCreateBox(gd3dDevice, 1.0f, 4.0f, 2.5f, &meshWindow2, NULL);	D3DXCreateBox(gd3dDevice, 1.0f, 3.0f, 8.0f, &meshDoor, NULL);	D3DXCreateTextureFromFileEx(gd3dDevice, "dirt_crackeddrysoft_df_.dds", D3DX_DEFAULT, D3DX_DEFAULT,                                 D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED,                                 D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texGround);	D3DXCreateTextureFromFileEx(gd3dDevice, "metal_rustyorangepaint_df_.dds", D3DX_DEFAULT, D3DX_DEFAULT,                                 D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED,                                 D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texStairs);	D3DXCreateTextureFromFileEx(gd3dDevice, "plastic_lumpyblue_df_.dds", D3DX_DEFAULT, D3DX_DEFAULT,                                 D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED,                                 D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texFloor);	D3DXCreateTextureFromFileEx(gd3dDevice, "wood_hardwood_df_.dds", D3DX_DEFAULT, D3DX_DEFAULT,                                 D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED,                                 D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texWall);    return;}void render_frame(void){    // clear the window to a deep blue    gd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0);	gd3dDevice->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);    gd3dDevice->BeginScene();    // begins the 3D scene        // select which vertex format we are using        gd3dDevice->SetFVF(CUSTOMFVF);    D3DXMATRIX matView;    // the view transform matrix	D3DXMATRIX matTranslate; //D3DXMatrixTranslation(&matTranslate, 12.0f, 4.0f, 0.0f); to use this function	D3DXMATRIX matScale; //D3DXMatrixScaling(&matScale, 2.0f, 2.0f, 2.0f); to use function	// Use d3ddev->SetTransform(D3DTS_WORLD, &matTranslate); to set whatever transformation to be used	D3DXMATRIX matRotateZ;    D3DXMatrixLookAtLH(&matView,                       &D3DXVECTOR3 (x, y, z),    // the camera position                       &D3DXVECTOR3 (x + 20.0f, y, 0.0f),    // the look-at position                       &D3DXVECTOR3 (0.0f, 0.0f, -1.0f));    // the up direction    gd3dDevice->SetTransform(D3DTS_VIEW, &matView);    // set the view transform to matView    D3DXMATRIX matProjection;     // the projection transform matrix    D3DXMatrixPerspectiveFovLH(&matProjection,                               D3DXToRadian(45),    // the horizontal field of view                               SCREEN_WIDTH / SCREEN_HEIGHT,     // the aspect ratio                                              1.0f,    // the near view-plane                               8192.0f);    // the far view-plane    gd3dDevice->SetTransform(D3DTS_PROJECTION, &matProjection);    // set the projection		        // select the vertex buffer to display        gd3dDevice->SetStreamSource(0, t_buffer, 0, sizeof(CUSTOMVERTEX));		gd3dDevice->SetTexture(0, texGround);		D3DXMatrixScaling(&matScale, 1.0f, 1.0f, 1.0f);		D3DXMatrixTranslation(&matTranslate, 0.0f, 0.0f, 0.5f);		gd3dDevice->SetTransform(D3DTS_WORLD, &(matTranslate * matScale));        // copy the vertex buffer to the back buffer        gd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);		gd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 4, 2);		if(objectPlacementMode == 0)		{			D3DXMatrixTranslation(&matTranslate, mousePositionX, mousePositionY, floorHeight - 4.0f);			D3DXMatrixRotationZ(&matRotateZ, D3DXToRadian(90.0f));			gd3dDevice->SetTransform(D3DTS_WORLD, &matTranslate);			if(XaxisAligned == true)				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));			meshWall->DrawSubset(0);		};		if(objectPlacementMode == 1)		{			D3DXMatrixTranslation(&matTranslate, mousePositionX, mousePositionY, floorHeight);			gd3dDevice->SetTransform(D3DTS_WORLD, &matTranslate);			meshFloor->DrawSubset(0);		};		if(objectPlacementMode == 2)		{			D3DXMatrixTranslation(&matTranslate, mousePositionX, mousePositionY, floorHeight);			gd3dDevice->SetTransform(D3DTS_WORLD, &matTranslate);			if(rotate == 0)			{				D3DXMatrixRotationZ(&matRotateZ, D3DXToRadian(0.0f));				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));			};			if(rotate == 1)			{				D3DXMatrixRotationZ(&matRotateZ, D3DXToRadian(90.0f));				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));			};			if(rotate == 2)			{				D3DXMatrixRotationZ(&matRotateZ, D3DXToRadian(180.0f));				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));			};			if(rotate == 3)			{				D3DXMatrixRotationZ(&matRotateZ, D3DXToRadian(270.0f));				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));			};			meshStair->DrawSubset(0);			if(rotate == 0)			{				D3DXMatrixTranslation(&matTranslate, mousePositionX + 1.0f, mousePositionY, floorHeight - 1.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, mousePositionX + 2.0f, mousePositionY, floorHeight - 2.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, mousePositionX + 3.0f, mousePositionY, floorHeight - 3.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, mousePositionX + 4.0f, mousePositionY, floorHeight - 4.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, mousePositionX + 5.0f, mousePositionY, floorHeight - 5.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, mousePositionX + 6.0f, mousePositionY, floorHeight - 6.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, mousePositionX + 7.0f, mousePositionY, floorHeight - 7.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);			};			if(rotate == 1)			{				D3DXMatrixTranslation(&matTranslate, mousePositionX, mousePositionY + 1.0f, floorHeight - 1.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, mousePositionX, mousePositionY + 2.0f, floorHeight - 2.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, mousePositionX, mousePositionY + 3.0f, floorHeight - 3.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, mousePositionX, mousePositionY + 4.0f, floorHeight - 4.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, mousePositionX, mousePositionY + 5.0f, floorHeight - 5.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, mousePositionX, mousePositionY + 6.0f, floorHeight - 6.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, mousePositionX, mousePositionY + 7.0f, floorHeight - 7.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);			};			if(rotate == 2)			{				D3DXMatrixTranslation(&matTranslate, mousePositionX - 1.0f, mousePositionY, floorHeight - 1.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, mousePositionX - 2.0f, mousePositionY, floorHeight - 2.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, mousePositionX - 3.0f, mousePositionY, floorHeight - 3.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, mousePositionX - 4.0f, mousePositionY, floorHeight - 4.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, mousePositionX - 5.0f, mousePositionY, floorHeight - 5.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, mousePositionX - 6.0f, mousePositionY, floorHeight - 6.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, mousePositionX - 7.0f, mousePositionY, floorHeight - 7.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);			};			if(rotate == 3)			{				D3DXMatrixTranslation(&matTranslate, mousePositionX, mousePositionY - 1.0f, floorHeight - 1.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, mousePositionX, mousePositionY - 2.0f, floorHeight - 2.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, mousePositionX, mousePositionY - 3.0f, floorHeight - 3.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, mousePositionX, mousePositionY - 4.0f, floorHeight - 4.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, mousePositionX, mousePositionY - 5.0f, floorHeight - 5.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, mousePositionX, mousePositionY - 6.0f, floorHeight - 6.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, mousePositionX, mousePositionY - 7.0f, floorHeight - 7.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);			};		};		if(objectPlacementMode == 3)		{			if(XaxisAligned == false)			{				D3DXMatrixTranslation(&matTranslate, mousePositionX, mousePositionY + 3.0f, floorHeight - 4.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &matTranslate);				meshWindow1->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, mousePositionX, mousePositionY - 3.0f, floorHeight - 4.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &matTranslate);				meshWindow1->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, mousePositionX, mousePositionY, floorHeight - 1.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &matTranslate);				meshWindow2->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, mousePositionX, mousePositionY, floorHeight - 7.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &matTranslate);				meshWindow2->DrawSubset(0);			};			if(XaxisAligned == true)			{				D3DXMatrixRotationZ(&matRotateZ, D3DXToRadian(90.0f));				D3DXMatrixTranslation(&matTranslate, mousePositionX + 3.0f, mousePositionY, floorHeight - 4.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshWindow1->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, mousePositionX - 3.0f, mousePositionY, floorHeight - 4.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshWindow1->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, mousePositionX, mousePositionY, floorHeight - 1.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshWindow2->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, mousePositionX, mousePositionY, floorHeight - 7.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshWindow2->DrawSubset(0);			};		};		if(objectPlacementMode == 4)		{			D3DXMatrixTranslation(&matTranslate, mousePositionX, mousePositionY, floorHeight - 4.0f);			D3DXMatrixRotationZ(&matRotateZ, D3DXToRadian(90.0f));			gd3dDevice->SetTransform(D3DTS_WORLD, &matTranslate);			if(XaxisAligned == true)				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));			meshDoor->DrawSubset(0);		};			gd3dDevice->SetTexture(0, texWall);		while(wallBeingDrawn <= numberWalls - 1)		{			D3DXMatrixTranslation(&matTranslate, wall[wallBeingDrawn].positionX, wall[wallBeingDrawn].positionY, wall[wallBeingDrawn].positionZ);			D3DXMatrixRotationZ(&matRotateZ, D3DXToRadian(90.0f));			gd3dDevice->SetTransform(D3DTS_WORLD, &matTranslate);			if(wall[wallBeingDrawn].Xaxis == true)				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));			if(wall[wallBeingDrawn].positionZ >= floorHeight - 6.0f)				meshWall->DrawSubset(0);			wallBeingDrawn += 1;		}	wallBeingDrawn = 0;		while(windowBeingDrawn <= numberWindows - 1)		{			if(windows[windowBeingDrawn].Xaxis == false)			{				D3DXMatrixTranslation(&matTranslate, windows[windowBeingDrawn].positionX, windows[windowBeingDrawn].positionY + 3.0f, windows[windowBeingDrawn].positionZ);				gd3dDevice->SetTransform(D3DTS_WORLD, &matTranslate);				if(windows[windowBeingDrawn].positionZ >= floorHeight - 6.0f)					meshWindow1->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, windows[windowBeingDrawn].positionX, windows[windowBeingDrawn].positionY - 3.0f, windows[windowBeingDrawn].positionZ);				gd3dDevice->SetTransform(D3DTS_WORLD, &matTranslate);				if(windows[windowBeingDrawn].positionZ >= floorHeight - 6.0f)					meshWindow1->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, windows[windowBeingDrawn].positionX, windows[windowBeingDrawn].positionY, windows[windowBeingDrawn].positionZ + 3.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &matTranslate);				if(windows[windowBeingDrawn].positionZ >= floorHeight - 6.0f)					meshWindow2->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, windows[windowBeingDrawn].positionX, windows[windowBeingDrawn].positionY, windows[windowBeingDrawn].positionZ - 3.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &matTranslate);				if(windows[windowBeingDrawn].positionZ >= floorHeight - 6.0f)					meshWindow2->DrawSubset(0);			};			if(windows[windowBeingDrawn].Xaxis == true)			{				D3DXMatrixRotationZ(&matRotateZ, D3DXToRadian(90.0f));				D3DXMatrixTranslation(&matTranslate, windows[windowBeingDrawn].positionX + 3.0f, windows[windowBeingDrawn].positionY, windows[windowBeingDrawn].positionZ);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				if(windows[windowBeingDrawn].positionZ >= floorHeight - 6.0f)					meshWindow1->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, windows[windowBeingDrawn].positionX - 3.0f, windows[windowBeingDrawn].positionY, windows[windowBeingDrawn].positionZ);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				if(windows[windowBeingDrawn].positionZ >= floorHeight - 6.0f)					meshWindow1->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, windows[windowBeingDrawn].positionX, windows[windowBeingDrawn].positionY, windows[windowBeingDrawn].positionZ + 3.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				if(windows[windowBeingDrawn].positionZ >= floorHeight - 6.0f)					meshWindow2->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, windows[windowBeingDrawn].positionX, windows[windowBeingDrawn].positionY, windows[windowBeingDrawn].positionZ - 3.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				if(windows[windowBeingDrawn].positionZ >= floorHeight - 6.0f)					meshWindow2->DrawSubset(0);			};			windowBeingDrawn += 1;		}	windowBeingDrawn = 0;	gd3dDevice->SetTexture(0, texFloor);	while(floorBeingDrawn <= numberFloors - 1)	{		D3DXMatrixTranslation(&matTranslate, floors[floorBeingDrawn].positionX, floors[floorBeingDrawn].positionY, floors[floorBeingDrawn].positionZ);		gd3dDevice->SetTransform(D3DTS_WORLD, &matTranslate);		if(floors[floorBeingDrawn].positionZ >= floorHeight - 6.0f)			meshFloor->DrawSubset(0);		floorBeingDrawn += 1;	}		floorBeingDrawn = 0;	while(doorBeingDrawn <= numberDoors - 1)		{			D3DXMatrixTranslation(&matTranslate, door[doorBeingDrawn].positionX, door[doorBeingDrawn].positionY, door[doorBeingDrawn].positionZ);			D3DXMatrixRotationZ(&matRotateZ, D3DXToRadian(90.0f));			gd3dDevice->SetTransform(D3DTS_WORLD, &matTranslate);			if(door[doorBeingDrawn].Xaxis == true)				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));			if(door[doorBeingDrawn].positionZ >= floorHeight - 6.0f)				meshDoor->DrawSubset(0);			doorBeingDrawn += 1;		}	doorBeingDrawn = 0;	gd3dDevice->SetTexture(0, texStairs);	while(stairBeingDrawn <= numberStairs - 1)	{		if(stairs[stairBeingDrawn].positionZ >= floorHeight - 6.0f)		{		D3DXMatrixTranslation(&matTranslate, stairs[stairBeingDrawn].positionX, stairs[stairBeingDrawn].positionY, stairs[stairBeingDrawn].positionZ);			if(stairs[stairBeingDrawn].Xaxis == 0)			{				D3DXMatrixRotationZ(&matRotateZ, D3DXToRadian(0.0f));				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));			};			if(stairs[stairBeingDrawn].Xaxis == 1)			{				D3DXMatrixRotationZ(&matRotateZ, D3DXToRadian(90.0f));				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));			};			if(stairs[stairBeingDrawn].Xaxis == 2)			{				D3DXMatrixRotationZ(&matRotateZ, D3DXToRadian(180.0f));				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));			};			if(stairs[stairBeingDrawn].Xaxis == 3)			{				D3DXMatrixRotationZ(&matRotateZ, D3DXToRadian(270.0f));				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));			};			meshStair->DrawSubset(0);			if(stairs[stairBeingDrawn].Xaxis == 0)			{				D3DXMatrixTranslation(&matTranslate, stairs[stairBeingDrawn].positionX + 1.0f, stairs[stairBeingDrawn].positionY, stairs[stairBeingDrawn].positionZ - 1.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, stairs[stairBeingDrawn].positionX + 2.0f, stairs[stairBeingDrawn].positionY, stairs[stairBeingDrawn].positionZ - 2.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, stairs[stairBeingDrawn].positionX + 3.0f, stairs[stairBeingDrawn].positionY, stairs[stairBeingDrawn].positionZ - 3.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, stairs[stairBeingDrawn].positionX + 4.0f, stairs[stairBeingDrawn].positionY, stairs[stairBeingDrawn].positionZ - 4.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, stairs[stairBeingDrawn].positionX + 5.0f, stairs[stairBeingDrawn].positionY, stairs[stairBeingDrawn].positionZ - 5.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, stairs[stairBeingDrawn].positionX + 6.0f, stairs[stairBeingDrawn].positionY, stairs[stairBeingDrawn].positionZ - 6.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, stairs[stairBeingDrawn].positionX + 7.0f, stairs[stairBeingDrawn].positionY, stairs[stairBeingDrawn].positionZ - 7.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);			};			if(stairs[stairBeingDrawn].Xaxis == 1)			{				D3DXMatrixTranslation(&matTranslate, stairs[stairBeingDrawn].positionX, stairs[stairBeingDrawn].positionY + 1.0f, stairs[stairBeingDrawn].positionZ - 1.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, stairs[stairBeingDrawn].positionX, stairs[stairBeingDrawn].positionY + 2.0f, stairs[stairBeingDrawn].positionZ - 2.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, stairs[stairBeingDrawn].positionX, stairs[stairBeingDrawn].positionY + 3.0f, stairs[stairBeingDrawn].positionZ - 3.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, stairs[stairBeingDrawn].positionX, stairs[stairBeingDrawn].positionY + 4.0f, stairs[stairBeingDrawn].positionZ - 4.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, stairs[stairBeingDrawn].positionX, stairs[stairBeingDrawn].positionY + 5.0f, stairs[stairBeingDrawn].positionZ - 5.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, stairs[stairBeingDrawn].positionX, stairs[stairBeingDrawn].positionY + 6.0f, stairs[stairBeingDrawn].positionZ - 6.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, stairs[stairBeingDrawn].positionX, stairs[stairBeingDrawn].positionY + 7.0f, stairs[stairBeingDrawn].positionZ - 7.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);			};			if(stairs[stairBeingDrawn].Xaxis == 2)			{				D3DXMatrixTranslation(&matTranslate, stairs[stairBeingDrawn].positionX - 1.0f, stairs[stairBeingDrawn].positionY, stairs[stairBeingDrawn].positionZ - 1.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, stairs[stairBeingDrawn].positionX - 2.0f, stairs[stairBeingDrawn].positionY, stairs[stairBeingDrawn].positionZ - 2.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, stairs[stairBeingDrawn].positionX - 3.0f, stairs[stairBeingDrawn].positionY, stairs[stairBeingDrawn].positionZ - 3.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, stairs[stairBeingDrawn].positionX - 4.0f, stairs[stairBeingDrawn].positionY, stairs[stairBeingDrawn].positionZ - 4.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, stairs[stairBeingDrawn].positionX - 5.0f, stairs[stairBeingDrawn].positionY, stairs[stairBeingDrawn].positionZ - 5.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, stairs[stairBeingDrawn].positionX - 6.0f, stairs[stairBeingDrawn].positionY, stairs[stairBeingDrawn].positionZ - 6.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, stairs[stairBeingDrawn].positionX - 7.0f, stairs[stairBeingDrawn].positionY, stairs[stairBeingDrawn].positionZ - 7.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);			};			if(stairs[stairBeingDrawn].Xaxis == 3)			{				D3DXMatrixTranslation(&matTranslate, stairs[stairBeingDrawn].positionX, stairs[stairBeingDrawn].positionY - 1.0f, stairs[stairBeingDrawn].positionZ - 1.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, stairs[stairBeingDrawn].positionX, stairs[stairBeingDrawn].positionY - 2.0f, stairs[stairBeingDrawn].positionZ - 2.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, stairs[stairBeingDrawn].positionX, stairs[stairBeingDrawn].positionY - 3.0f, stairs[stairBeingDrawn].positionZ - 3.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, stairs[stairBeingDrawn].positionX, stairs[stairBeingDrawn].positionY - 4.0f, stairs[stairBeingDrawn].positionZ - 4.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, stairs[stairBeingDrawn].positionX, stairs[stairBeingDrawn].positionY - 5.0f, stairs[stairBeingDrawn].positionZ - 5.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, stairs[stairBeingDrawn].positionX, stairs[stairBeingDrawn].positionY - 6.0f, stairs[stairBeingDrawn].positionZ - 6.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);				D3DXMatrixTranslation(&matTranslate, stairs[stairBeingDrawn].positionX, stairs[stairBeingDrawn].positionY - 7.0f, stairs[stairBeingDrawn].positionZ - 7.0f);				gd3dDevice->SetTransform(D3DTS_WORLD, &(matRotateZ * matTranslate));				meshStair->DrawSubset(0);			};			};			stairBeingDrawn += 1;	}	stairBeingDrawn = 0;	RECT R = {5, 5, 0, 0};	mFont->DrawText(0, _T("Text"), -1, &R, DT_NOCLIP, D3DCOLOR_XRGB(0,0,0)); //it crashes here    gd3dDevice->EndScene();    // ends the 3D scene    gd3dDevice->Present(NULL, NULL, NULL, NULL);   // displays the created frame on the screen    return;}void cleanD3D(void){	mFont->Release();	meshWindow1->Release();	meshWindow2->Release();	meshStair->Release();	meshDoor->Release();	meshFloor->Release();	meshWall->Release();    gd3dDevice->Release(); // close and release the 3D device    d3d->Release(); // close and release Direct3D    return;}void initDInput(HINSTANCE hInstance, HWND hWnd){    // create the DirectInput interface    DirectInput8Create(hInstance,    // the handle to the application                       DIRECTINPUT_VERSION,    // the compatible version                       IID_IDirectInput8,    // the DirectInput interface version                       (void**)&din,    // the pointer to the interface                       NULL);    // COM stuff, so we'll set it to NULL    // create the keyboard device    din->CreateDevice(GUID_SysKeyboard,    // the default keyboard ID being used                      &dinkeyboard,    // the pointer to the device interface                      NULL);    // COM stuff, so we'll set it to NULL    dinkeyboard->SetDataFormat(&c_dfDIKeyboard); // set the data format to keyboard format    // set the control you will have over the keyboard    dinkeyboard->SetCooperativeLevel(hWnd,                                     DISCL_NONEXCLUSIVE | DISCL_BACKGROUND);	din->CreateDevice(GUID_SysMouse,    // the default mouse ID being used                      &dinmouse,    // the pointer to the device interface                      NULL);    // COM stuff, so we'll set it to NULL	dinmouse->SetDataFormat(&c_dfDIMouse);    // set the data format to mouse format	// set the control you will have over the mouse    dinmouse->SetCooperativeLevel(hWnd,                                  DISCL_NONEXCLUSIVE | DISCL_BACKGROUND);	dinmouse->Acquire();    // Acquire the mouse only once      return;    // return to WinMain()}void cleanDInput(void){    dinkeyboard->Unacquire();    // make sure the keyboard is unacquired	dinmouse->Unacquire();    // make sure the mouse is unacquired    din->Release();    // close DirectInput before exiting    return;}void init_graphics(void){    // create the vertices using the CUSTOMVERTEX struct    CUSTOMVERTEX t_vert[] =    {		{ 64.0f, -64.0f, 0.5f, D3DCOLOR_XRGB(255, 255, 255), 0, 75,},        { -64.0f, -64.0f, 0.5f, D3DCOLOR_XRGB(255, 255, 255), 75, 75,},		{ 64.0f, 64.0f, 0.5f, D3DCOLOR_XRGB(255, 255, 255), 0, 0,},        { -64.0f, 64.0f, 0.5f, D3DCOLOR_XRGB(255, 255, 255), 75, 0,},		//cursor		{ mousePositionX, mousePositionY + 2.0f, floorHeight, D3DCOLOR_XRGB(255, 255, 255),},		{ mousePositionX + 2.0f, mousePositionY + 2.0f, floorHeight, D3DCOLOR_XRGB(255, 255, 255),},		{ mousePositionX, mousePositionY, floorHeight, D3DCOLOR_XRGB(255, 255, 255),},		{ mousePositionX + 2.0f, mousePositionY, floorHeight, D3DCOLOR_XRGB(255, 255, 255),},    };    // create a vertex buffer interface called t_buffer    gd3dDevice->CreateVertexBuffer(8*sizeof(CUSTOMVERTEX),                               0,                               CUSTOMFVF,                               D3DPOOL_MANAGED,                               &t_buffer,                               NULL);    VOID* pVoid;    // a void pointer    // lock t_buffer and load the vertices into it    t_buffer->Lock(0, 0, (void**)&pVoid, 0);    memcpy(pVoid, t_vert, sizeof(t_vert));    t_buffer->Unlock();    return;}void loadBuilding(){	return;}void saveBuilding(){	return;}void detect_mousepos(void){    static DIMOUSESTATE mousestate;    // create a static storage for the mouse-states    dinmouse->Acquire();    // get access if we don't have it already    // fill the mousestate with values    dinmouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&mousestate);	mousePositionY = mousePositionY - mousestate.lX / 5;	mousePositionX = mousePositionX - mousestate.lY / 5;	if(mousePositionX >= 65.0f)		mousePositionX = 62.0f;	if(mousePositionY >= 65.0f)		mousePositionY = 62.0f;	if(mousePositionX <= -65.0f)		mousePositionX = -62.0f;	if(mousePositionY <= -65.0f)		mousePositionY = -62.0f;	if(mousestate.rgbButtons[0] & 0x80)	{		if(objectPlacementMode == 0)		{			if(XaxisAligned == false)			{				wall[numberWalls].positionX = mousePositionX;				wall[numberWalls].positionY = mousePositionY;				wall[numberWalls].positionZ = floorHeight - 4.0f;				wall[numberWalls].Xaxis = false;			};			if(XaxisAligned == true)			{				wall[numberWalls].positionX = mousePositionX;				wall[numberWalls].positionY = mousePositionY;				wall[numberWalls].positionZ = floorHeight - 4.0f;				wall[numberWalls].Xaxis = true;			};			numberWalls += 1;			while(wallBeingChecked <= numberWalls - 2 && checkFailed != true)			{				if(wall[wallBeingChecked].positionX == wall[numberWalls - 1].positionX && wall[wallBeingChecked].positionY == wall[numberWalls - 1].positionY && wall[wallBeingChecked].positionZ == wall[numberWalls - 1].positionZ &&wall[wallBeingChecked].Xaxis == wall[numberWalls - 1].Xaxis)					checkFailed = true;				wallBeingChecked += 1;			}			if(checkFailed == true)				numberWalls -= 1;			wallBeingChecked = 0;			checkFailed = false;			if(numberWalls >= 16392)				numberWalls = 16392;			maxredowall = numberWalls;		};		if(objectPlacementMode == 1)			{				floors[numberFloors].positionX = mousePositionX;				floors[numberFloors].positionY = mousePositionY;				floors[numberFloors].positionZ = floorHeight;				numberFloors += 1;			while(floorBeingChecked <= numberFloors - 2 && checkFailed != true)			{				if(floors[floorBeingChecked].positionX == floors[numberFloors - 1].positionX && floors[floorBeingChecked].positionY == floors[numberFloors - 1].positionY && floors[floorBeingChecked].positionZ == floors[numberFloors - 1].positionZ)					checkFailed = true;				floorBeingChecked += 1;			}			if(checkFailed == true)				numberFloors -= 1;			floorBeingChecked = 0;			checkFailed = false;			if(numberFloors >= 262144)				numberFloors = 262144;			maxredofloor = numberFloors;			};		if(objectPlacementMode == 2)		{						if(rotate == 0)			{				stairs[numberStairs].positionX = mousePositionX;				stairs[numberStairs].positionY = mousePositionY;				stairs[numberStairs].positionZ = floorHeight;				stairs[numberStairs].Xaxis = 0;			};			if(rotate == 1)			{				stairs[numberStairs].positionX = mousePositionX;				stairs[numberStairs].positionY = mousePositionY;				stairs[numberStairs].positionZ = floorHeight;				stairs[numberStairs].Xaxis = 1;			};if(rotate == 2)			{				stairs[numberStairs].positionX = mousePositionX;				stairs[numberStairs].positionY = mousePositionY;				stairs[numberStairs].positionZ = floorHeight;				stairs[numberStairs].Xaxis = 2;			};			if(rotate == 3)			{				stairs[numberStairs].positionX = mousePositionX;				stairs[numberStairs].positionY = mousePositionY;				stairs[numberStairs].positionZ = floorHeight;				stairs[numberStairs].Xaxis = 3;			};			numberStairs += 1;			while(stairsBeingChecked <= numberStairs - 2 && checkFailed != true)			{				if(stairs[stairsBeingChecked].positionX == stairs[numberStairs - 1].positionX && stairs[stairsBeingChecked].positionY == stairs[numberStairs - 1].positionY && stairs[stairsBeingChecked].positionZ == stairs[numberStairs - 1].positionZ && stairs[stairsBeingChecked].Xaxis == stairs[numberStairs - 1].Xaxis)					checkFailed = true;				stairsBeingChecked += 1;			}			if(checkFailed == true)				numberStairs -= 1;			stairsBeingChecked = 0;			checkFailed = false;			if(numberStairs >= 2048)				numberStairs = 2047;			maxredostairs = numberStairs;		};		if(objectPlacementMode == 3)		{			if(XaxisAligned == false)			{				windows[numberWindows].positionX = mousePositionX;				windows[numberWindows].positionY = mousePositionY;				windows[numberWindows].positionZ = floorHeight - 4.0f;				windows[numberWindows].Xaxis = false;			};			if(XaxisAligned == true)			{				windows[numberWindows].positionX = mousePositionX;				windows[numberWindows].positionY = mousePositionY;				windows[numberWindows].positionZ = floorHeight - 4.0f;				windows[numberWindows].Xaxis = true;			};			numberWindows += 1;			while(windowBeingChecked <= numberWindows - 2 && checkFailed != true)			{				if(windows[windowBeingChecked].positionX == windows[numberWindows - 1].positionX && windows[windowBeingChecked].positionY == windows[numberWindows - 1].positionY && windows[windowBeingChecked].positionZ == windows[numberWindows - 1].positionZ && windows[windowBeingChecked].Xaxis == windows[numberWindows - 1].Xaxis)					checkFailed = true;				windowBeingChecked += 1;			}			if(checkFailed == true)				numberWindows -= 1;			windowBeingChecked = 0;			checkFailed = false;			if(numberWindows >= 2048)				numberWindows = 2047;			maxredowindows = numberWindows;		};		if(objectPlacementMode == 4)		{			if(XaxisAligned == false)			{				door[numberDoors].positionX = mousePositionX;				door[numberDoors].positionY = mousePositionY;				door[numberDoors].positionZ = floorHeight - 4.0f;				door[numberDoors].Xaxis = false;			};			if(XaxisAligned == true)			{				door[numberDoors].positionX = mousePositionX;				door[numberDoors].positionY = mousePositionY;				door[numberDoors].positionZ = floorHeight - 4.0f;				door[numberDoors].Xaxis = true;			};			numberDoors += 1;			while(doorBeingChecked <= numberDoors - 2 && checkFailed != true)			{				if(door[doorBeingChecked].positionX == door[numberDoors - 1].positionX && door[doorBeingChecked].positionY == door[numberDoors - 1].positionY && door[doorBeingChecked].positionZ == door[numberDoors - 1].positionZ && door[doorBeingChecked].Xaxis == door[numberDoors - 1].Xaxis)					checkFailed = true;				doorBeingChecked += 1;			}			if(checkFailed == true)				numberDoors -= 1;			doorBeingChecked = 0;			checkFailed = false;			if(numberDoors >= 2048)				numberDoors = 2047;			maxredodoors = numberDoors;		};	};	if(checkFrame == 0 || doCheckFrame == false)	{		if(mousestate.rgbButtons[2] & 0x80)		{			if(XaxisAligned == false)				XaxisAligned = true;			else				XaxisAligned = false;			rotate += 1;			if(rotate >= 4)				rotate = 0;			doCheckFrame = true;		}	};    return;}//This program is just a test


[EDIT: Added Source Tags for everybodies enjoyment]

[Edited by - dwarfsoft on February 21, 2007 3:27:51 AM]
Evil Steve
Evil Steve
You're not checking the return values of ANY of your Direct3D functions. If something goes wrong, D3D tells you by returning an error code. You're just effectively giving D3D the finger and assuming everything works fine. Which it doesn't, because D3DXCreateFontIndirect() is failing - As you'd see if you'd used the FAILED macro as people have suggested.
Because D3DXCreateFontIndirect() failes, your font pointer is NULL, which causes an access violation (0xc0000005) reading from the null pointer (location 0x00000000).

You should also use the debug runtimes, and link to d3dx9d.lib which will give you more error information in the debug output, such as telling you WHY the function failed.

Also, please use [ source ] [ /source ] tags when posting large chunks of text. It formats it nicely, and means people don't have to scroll down pages and pages to see the thread.

Topic Locked

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

Sign in to reply to this topic.