I been trying to solve this by my own, but it simply don't make any sence. I'm trying to do the required initializing of the necessary D3DX components, so I can use the Sprite interface and draw an image. The main code runs fine, but as soon as the loop reaches the Graphics class, it crashes. Here's my code:
Graphics.cpp
[source lang="cpp"]
#include "Graphics.h"
Graphics::Graphics(HWND hWnd)
{
d3d = Direct3DCreate9(D3D_SDK_VERSION);
ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS));
d3dpp.Windowed = true;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hWnd;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.BackBufferWidth = 1280;
d3dpp.BackBufferHeight = 800;
D3DXCreateSprite(d3ddev, &sprite);
d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);
}
Graphics::~Graphics(void)
{
}
// --------------------------------------------------------------------------------
// Name: Begin
// Desc:
// Rtrn: None
// --------------------------------------------------------------------------------
void Graphics::Begin(void)
{
sprite->Begin(D3DXSPRITE_ALPHABLEND);
}
// --------------------------------------------------------------------------------
// Name: Draw
// Desc:
// Rtrn: None
// --------------------------------------------------------------------------------
void Graphics::Draw(void)
{
}
// --------------------------------------------------------------------------------
// Name: End
// Desc:
// Rtrn: None
// --------------------------------------------------------------------------------
void Graphics::End(void)
{
sprite->End();
}
[/source]
Graphics.h
[source lang="cpp"]
#pragma once
#include <d3d9.h>
#include <d3dx9.h>
#pragma comment (lib, "d3d9.lib")
#pragma comment (lib, "d3dx9.lib")
class Graphics
{
public:
Graphics(HWND hWnd);
~Graphics(void);
// --------------------------------------------------------------------------------
// Name: Begin
// Desc:
// Rtrn: None
// --------------------------------------------------------------------------------
void Begin(void);
// --------------------------------------------------------------------------------
// Name: Draw
// Desc:
// Rtrn: None
// --------------------------------------------------------------------------------
void Draw(void);
// --------------------------------------------------------------------------------
// Name: End
// Desc:
// Rtrn: None
// --------------------------------------------------------------------------------
void End(void);
private:
LPDIRECT3D9 d3d;
D3DPRESENT_PARAMETERS d3dpp;
LPDIRECT3DDEVICE9 d3ddev;
LPD3DXSPRITE sprite;
};
[/source]
Nothing is null here, right? Still I get this error on crash:
Unhandled exception at 0x0fd49c2d in AvoidBall.exe: 0xC0000005: Access violation reading location 0xcdcdcdcd.
The "green arrow" stops on the 19:th line:
d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);
What am I doing wrong? I know that I've asked alot about this basic graphics code, but it simply won't work for me Please help!