Hey GameDev
So I just attempted making a Breakout clone, but I did not get far at all when I got an error I've not dealt with before.
When I debug my completely blank window, I get this outputting:
First-chance exception at 0x74cdc41f in Breakout.exe: Microsoft C++ exception: long at memory location 0x003af9e0..
I stepped through the code, and it seems to be spawning from this line:
d3dDevice->Present(NULL, NULL, NULL, NULL);
here's my full source so far, I don't understand what's happening as I'm doing everything as I normally do:
//Winmain cpp
#include <Windows.h>
#include <d3d9.h>
#include <d3dx9.h>
#pragma comment (lib, "d3d9.lib")
#pragma comment (lib, "d3dx9.lib")
#pragma comment (lib, "winmm.lib")
LPDIRECT3D9 d3d;
LPDIRECT3DDEVICE9 d3dDevice;
LPD3DXSPRITE spriteMachine;
LPARAM CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
void InitializeD3D(HWND hWnd);
void Pulse(DWORD delta);
void KillD3D();
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
HWND hWnd;
WNDCLASSEX wc;
DWORD delta = 0;
DWORD prevFrameTime = 0;
DWORD thisFrameTime = 0;
ZeroMemory(&wc, sizeof(WNDCLASSEX));
wc.cbSize = sizeof(WNDCLASSEX);
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.hCursor = LoadCursor(0, IDC_ARROW);
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.lpszClassName = L"WINDOW";
wc.style = CS_HREDRAW | CS_VREDRAW;
RegisterClassEx(&wc);
hWnd = CreateWindowEx(
NULL, L"WINDOW", L"Breakout Clone",
WS_OVERLAPPED | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU, 0, 0, 800, 600,
NULL, NULL, hInstance, NULL);
ShowWindow(hWnd, nShowCmd);
MSG msg = {0};
InitializeD3D(hWnd);
while (true)
{
thisFrameTime = timeGetTime();
if(prevFrameTime != 0)
delta = thisFrameTime - prevFrameTime;
else delta = 0;
prevFrameTime = thisFrameTime;
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
if (msg.message == WM_QUIT)
break;
}
Pulse(delta);
}
KillD3D();
return msg.wParam;
}
LPARAM CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
break;
}
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
void InitializeD3D(HWND hWnd)
{
d3d = Direct3DCreate9(D3D_SDK_VERSION);
D3DPRESENT_PARAMETERS d3dPP;
ZeroMemory(&d3dPP, sizeof(D3DPRESENT_PARAMETERS));
d3dPP.BackBufferWidth = 800;
d3dPP.BackBufferHeight = 600;
d3dPP.hDeviceWindow = hWnd;
d3dPP.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dPP.Windowed = true;
d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dPP, &d3dDevice);
D3DXCreateSprite(d3dDevice, &spriteMachine);
}
void Pulse(DWORD delta)
{
d3dDevice->Clear(0, 0, D3DCLEAR_TARGET, 0x000000, 1, 0);
d3dDevice->BeginScene();
spriteMachine->Begin(D3DXSPRITE_ALPHABLEND);
spriteMachine->End();
d3dDevice->EndScene();
d3dDevice->Present(NULL, NULL, NULL, NULL);
}
void KillD3D()
{
spriteMachine->Release();
d3dDevice->Release();
d3d->Release();
}