• Advertisement
Sign in to follow this  

What does this mean, and how can I fix it?

This topic is 1780 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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();
}

Share this post


Link to post
Share on other sites
Advertisement

Switch D3D to the debug runtime (search the D3D documentation for 'debug'). You'll get more detailed error messages.

 

That seemed to eliminate the problem all together, so thanks :)

Share this post


Link to post
Share on other sites

 


Switch D3D to the debug runtime (search the D3D documentation for 'debug'). You'll get more detailed error messages.


That seemed to eliminate the problem all together, so thanks smile.png

That's not the idea. It's supposed to help find the error, not allow you to ignore it.

Make sure "break on D3D error" is turned on.

 

 

I've turned directx into debug mode, and the break on d3d error is also enabled, but now it runs like there is no error at all. Nothing comes out of the output that I see as unusual. If I had of remembered to turn it to debug mode in the first place, I never would have even seen this error. What should I do? How do I find/fix it?

 

 

 

And also turn up the message to one tick below informational, you will get flooded otherwise, any warning that comes out of those messages should be fixed in a release build.

 

Sorry I'm not sure what you mean

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement