Sprites and D3D9

Started by
30 comments, last by falcon93 12 years, 7 months ago
Hi!

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!
Advertisement
can you get the result of thos D3D creation calls ?
because checking the return values of D3D is very important, and dont forget to try the D3D Debug runtimes.
they help a lot.

Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

I know how to get the HRESULT from the method, but how do I check the actual info of the HRESULT? I can't write the HRESULT in a messagebox? Is there any smarter way then checking with a switch?

[color="#1C2837"]D3D Debug runtimes? How do I use it?

I know how to get the HRESULT from the method, but how do I check the actual info of the HRESULT? I can't write the HRESULT in a messagebox? Is there any smarter way then checking with a switch?


it would be quicker to set a break point and copy the value of the HRESULT and look it up in the DirectX Error Lookup tool / google.


[color="#1C2837"]D3D Debug runtimes? How do I use it?


goto the Microsoft DirectX SDK folder in the StartMenu -> then in the
startmenu -> Microsoft DirectX SDK( whatever version your using ) -> DirectX Utilities -> DirectX Control Panel.
then set the debug out put and select "use debug runtimes" option.
then run your game again and check the "output window" of the IDE for the info from D3D.

Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

[color=#1C2837][size=2]
it would be quicker to set a break point and copy the value of the HRESULT and look it up in the DirectX Error Lookup tool / google.[/quote]
[color=#1C2837][size=2]

[color=#1C2837][size=2]Sorry, but, how do I set a break point? And how can I copy the value of the HRESULT? Sorry, but I've never done this before, first time I even hear about it :/
[color=#1C2837][size=2]

[color=#1C2837][size=2]

[color="#1C2837"]
it would be quicker to set a break point and copy the value of the HRESULT and look it up in the DirectX Error Lookup tool / google.

[color="#1C2837"]
[color="#1C2837"]Sorry, but, how do I set a break point? And how can I copy the value of the HRESULT? Sorry, but I've never done this before, first time I even hear about it :/
[color="#1C2837"]
[color="#1C2837"]
[/quote]

to set a break point( in VS ) click in the light brown line on the left of the code page, or there should be a add break point here button
when the break point hits, hold the mouse over the hresult and a little box should pop up, select the text in there and copy it.

Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

Thank you very much, I've learned something new :D

The question now is how I should use this number?


-858993460



The DirectX Error Lookup tool does only provide this:


HRESULT: 0xa766cb98 (2808531864)
Name: Unknown
Description: n/a
Severity code: Failed
Facility Code: Unknown (1894)
Error Code: 0xcb98 (52120)



Putting this number into google won't give any good results. What should I do with it?

try running this code.

TDWORD error = GetLastError();
LPTSTR errorText = NULL;

FormatMessage(
// use system message tables to retrieve error text
FORMAT_MESSAGE_FROM_SYSTEM
// allocate buffer on local heap for error text
|FORMAT_MESSAGE_ALLOCATE_BUFFER
// Important! will fail otherwise, since we're not
// (and CANNOT) pass insertion parameters
|FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, // unused with FORMAT_MESSAGE_FROM_SYSTEM
error,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&errorText, // output
0, // minimum size for output buffer
NULL); // arguments - see note

wstring ws( errorText );
string errorstring( ws.begin(), ws.end() );

MessageBoxA( NULL, errorstring.c_str(), "Error", MB_OK );


maybve it is a Win32 Error.

also check if the interfaces are NULL or nullpre( C++0x )
what about the debug runtimes ?

Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

You must create the sprite before using it. During Initialization call the D3DXCreateSprite() function after creating the device.
What header do I have to include to use TDWORD and wstring? Also, I've checked for null values with if statements but didin't find any.

Regarding the Debug Runtimes. This is the window, but now I don't know what to change? Your path worked untill this window :P
hw0qcy.jpg



@Aerodactyl55:[color="#1c2837"] I'm calling it?
[color="#1c2837"]
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);

HRESULT hr = d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);
}



Thank you btoh for helping me appreciated :)

This topic is closed to new replies.

Advertisement