Jump to content
  • Advertisement
Sign in to follow this  
falcon93

Sprites and D3D9

This topic is 2669 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

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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
[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]

Share this post


Link to post
Share on other sites

[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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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 ?

Share this post


Link to post
Share on other sites
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 :)

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!