0

So I am trying to clear a window to go completely blue, but for some reason D3D9 "Clear()" function won't work. I've done error checking so I know 100% that it's the Clear() function that's failing and not something else. I've checked it with code that I've previously coded that works, so I have no clue why this won't work. The return value of Clear() is "-2005530516", though I couldn't find anything online about what that means. Any ideas?

#include "DirectX.h"

LPDIRECT3D9 d3d;
LPDIRECT3DDEVICE9 d3ddev;

int InitD3D(HWND hWnd)
{
    d3d = Direct3DCreate9(D3D_SDK_VERSION);

    if (d3d == nullptr)
        return -1;

    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory(&d3dpp, sizeof(d3dpp));

    d3dpp.Windowed = true;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.hDeviceWindow = hWnd;

    d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);

    if (d3ddev == nullptr)
        return -1;

    return 0;
}

int CreateBoard()
{
    D3DRECT rect;
    rect = { 100, 50, 200, 100 };
    
    //d3ddev->Clear(1, &rect, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 255), 1.0f, NULL);
    HRESULT result = d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 255), 1.0f, NULL);

    if (result == D3DERR_INVALIDCALL)
    {
        MessageBoxA(NULL, "ERROR: FAILED TO CLEAR", "ERROR", MB_ICONERROR);
        return result;
    }
    return 0;
}

void CleanD3D()
{
    d3d->Release();
    d3ddev->Release();
}
jacob
  • 35
  • 7

1 Answers1

2

The value "-2005530516" is a decimal version of an HRESULT (usually printed as a hexadecimal number). It's D3DERR_INVALIDCALL. Of course, you are assigning that value:

if (result = D3DERR_INVALIDCALL)

Did you mean?

if (result == D3DERR_INVALIDCALL)
Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81
  • Yep, I did. I have no idea how I missed that lol. Guess it isn't the Clear() function not working, I'll have to revisit my InitD3D function now. Do you see anything wrong with it? Thanks for finding that though. – jacob Sep 03 '20 at 21:17