Archived

This topic is now archived and is closed to further replies.

Problem with D3DX...

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

Does anyone know why I would be getting a DDERR_CANNOTATTACHSURFACE error when I attempt to create a D3DX context? My program registers/creates the window, then it calls D3DXInitialize(), checks the caps, and calls D3DXCreateContextEx(). I have tried both CreateContextEx and CreateContext, even with all defaults and I get the same thing each time. I have tried removing the caps check. I''ve tried making D3DXInitialize the very first call in WinMain. I''ve changed up some of the window reg/creation params. I always get the exact same error. The SDK explains the error as
quote:
A surface cannot be attached to another requested surface.
If anyone knows how to fix this, please enlighten me. Thanks in advance for the help. Oh... The SDK examples work fine. Imagine that!

Share this post


Link to post
Share on other sites
I''m using a Voodoo3 2000. I''ve tried many different combinations of parameters with both D3DXCreateContext() and D3DXCreateContextEx(). I''ve even tried supplying all D3DX_DEFAULT parameters where they are accepted. Does this tell you anything?

I''m taking a look at the tutorials now.
Thanks for the help.

Share this post


Link to post
Share on other sites
The Voodoo3 doesn''t have stencil buffers.

I believe one of the defaults for stencil buffer actually tries to make a stencil buffer. Make sure the parameter for stencil buffer is 0, and then make the rest default...

If that doesn''t work, try hard-coding WIDTH/HEIGHT to 640/480...

If that doesn''t work, specify a bit-depth of 16.
(if you specify defeault for bit depth, the context will default to the bit depth of your desktop, and if you run your desktop in 24 bit it will try to make a 24 bit bit depth)

If that doesn''t help try running your desktop in 16 bits.

If that doesn''t work, hmmm...

Share this post


Link to post
Share on other sites
Thanks for the help JoeyBlow2. Unfortunately, I had previously tried setting the stencil bits to zero. Doh! I also run my desktop in 16bit. And I want to create my D3DX object in 1024x768 preferably, but I have tried 640, 800, and 1024. This is bugging me. If it would help to take a look at some of my source, I would be more than willing to oblige. Once again, thanks for taking the time to try and help me out. I appreciate it.

Share this post


Link to post
Share on other sites
Well i have a voodoo 3 2000, try this:

            
D3DXCreateContext(D3DX_DEFAULT, D3DX_CONTEXT_FULLSCREEN,
hWnd, 1024, 768, &g_pd3dx);

or...

D3DXCreateContextEx(D3DX_DEFAULT,D3DX_CONTEXT_FULLSCREEN,
hWnd,NULL,16,D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,
D3DX_DEFAULT,1024,768,D3DX_DEFAULT,&g_pd3dx);



With D3DXCreateContextEx i run into a weird situation, if numAlphaBits,numDepthbits, or numStencilBits are set to NULL or 0 instead of D3DX_DEFAULT, i lose quite a few fps and there are graphical glitches in parts of my game.

BTW, g_pd3dx is my pointer to the ID3DXContext interface.

+AA_970+



Edited by - +AA_970+ on July 12, 2000 5:06:40 PM

Share this post


Link to post
Share on other sites
Thanks for the help +AA_970+, but I am still getting the same error. I''m not going to give up without figuring this out, but it''s really making me bitter. I''ve looked at all of the SDK examples and all of the tutorials that I''ve found, and I haven''t found any major differences in them and my code. It doesn''t matter exactly where I call D3DXInitialize() as long as it''s the first D3DX function that I call, right? The DirectX help and the SDK examples are somewhat unclear about this. I made it the very first call in WinMain, but that didn''t help. Currently, it''s the first call in my InitD3DX function which is called immediately after the window is created. Thanks for all the help. I''m gonna keep looking.

BTW, In case it makes any difference, I have the same code implemented in DDraw/D3D and it works great. I just figured that changing to D3DX would simplify things a little more.

Share this post


Link to post
Share on other sites
You said your had the code implemented in DDraw/D3D. Now that you switched to D3DX are you still starting up direct draw?
The D3DX context creates D3D and DDraw, so you wouldn't have to init. DDraw. You also don't have to do QueryInterface, SetCooperativeLevel, SetDisplayMode, create the primary surface, and create the back buffer.

+AA_970+

Edited by - +AA_970+ on July 13, 2000 12:24:45 PM

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Nope. I trashed the DDraw and D3D code when I changed to D3DX.

Share this post


Link to post
Share on other sites
Okay, this is ridiculous. I have simplified this as much as possible. Here's the important part of the source. Does anyone see anything wrong with it?

        
LPD3DXCONTEXT D3DXContext = NULL;
...
...
int PASCAL
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
fError = fopen("Error.log", "w"); // Open file for logging errors.


HRESULT hr;
hr = D3DXInitialize();
if ( FAILED(hr) ) LogError(hr);


// Set up and register the window class.

WNDCLASS wc = {0};

wc.lpfnWndProc = (WNDPROC) WindowProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
wc.lpszClassName = NAME;
RegisterClass(&wc);

// Create the window.

HWND hwnd;
hwnd = CreateWindow(NAME, TITLE, WS_POPUP, 0, 0, 800, 600,
(HWND) NULL, (HMENU) NULL, hInstance, NULL);
SetCursor(false); // Hide the cursor.

ShowWindow(hwnd, SW_SHOWNORMAL); // Display the window.

UpdateWindow(hwnd);


// Create the D3DX context

hr = D3DXCreateContext(D3DX_DEFAULT, D3DX_CONTEXT_FULLSCREEN, hwnd,
800, 600, &D3DXContext);
if ( FAILED(hr) ) LogError(hr);


What in the world is going on? I am still getting a DDERR_CANNOTATTACHSURFACE error and D3DXContext remains NULL after the call. I am linking with DDGUID.LIB, DDRAW.LIB, D3DIM.LIB, D3DXD.LIB, and DINPUT.LIB. I have all of the appropriate headers included. All of the SDK examples and all of the tutorials from the web work correctly. Why not this? BTW, I've tried linking with the retail version of the D3DX library also. It didn't work. I've also tried about evey possible combination of parameters with both D3DXCreateContext() and D3DXCreateContextEx() as well as many different CreateWindow() params, and I can't figure it out.


Edited by - Matthew02 on July 13, 2000 11:32:50 PM

Share this post


Link to post
Share on other sites
I am linking with d3dxd.lib which is the debug version of the library. I have tried d3dx.lib (retail version) though, and it didn't make any difference. And when I took out d3dim.lib, the program linked fine, but still gives the same error. This is the most stubborn problem... Thanks for all the help though. With hope, I'll figure the damned thing out. Anyway, if you think of anything else...

Edited by - Matthew02 on July 14, 2000 10:45:23 PM

Share this post


Link to post
Share on other sites
Are you using the latest Voodoo 3 drivers (1.05.00)?
Because my comp. has problems with the new drivers i''m using the 1.04.00, but i did try out the 1.05.00 drivers. Both drivers worked fine with D3D apps and D3DX. If your using the drivers off the cd you may need to download one of these drivers.

+AA_970+

Share this post


Link to post
Share on other sites
Sorry about not replying. I've been away for a couple of days. Anyway...
I'm downloading the newest drivers right now and I'll check those out. As for going back to d3dim, I may do that anyway, but I wish that I could understand what is going on here. Witchlord, you say you believe it could be a problem with d3dx or 3dfx, but explain this... All of the SDK examples compile and run correctly as do all of the internet tutorials that I've found thus far. I have even created a new project and just pasted in some code from a tutorial page (as opposed to downloading their project) and it worked fine.
The only place where d3dx doesn't work is in my project. This leads me to believe that there is a problem with my code, but +AA_970+ says the same code works fine on his computer. *shrugs*
You see... This is very strange.
I'm going to try with the new drivers *crosses fingers* and if that doesn't work, maybe I'll look for a MS e-mail where I can get some DirectX support. I doubt that I'll get a response from them, but it's sure worth a try. In the meantime, if you folks think of anything else, please let me know. I'm anxious to figure out what's I have done wrong (if anything).
Thanks again for all of your responses. I can't express how much I appreciate everyone taking their time to help me out.

Edited by - Matthew02 on July 18, 2000 11:57:23 PM

Share this post


Link to post
Share on other sites
Well, I installed updated drives for my Voodoo and guess what? It worked. Haha. That's funny. My whole problem has been drivers. *kicks self in head*
Thanks to everyone who replied. I really appreciate all of your help. There's just one lingering question... Why did the SDK examples work with the old drivers? Hmm...
Well, actually two lingering questions. If I use d3dx rather than d3dim, is it going to severely limit my audience? With the driver problem that I had, I am somewhat afraid to use d3dx. Are there d3d compatible devices which do not work with d3dx? I thought it worked on top of d3d and ddraw (just a helper library). Why would d3dim and ddraw work, but not d3dx?
Doh, that was more than two questions. Oh well... Anyway, thanks again.

Edited by - Matthew02 on July 24, 2000 12:42:19 AM

Share this post


Link to post
Share on other sites