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

## 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 on other sites
What type of card do you have, and what parameters are you giving D3DXCreateContext()?

Maybe you can get some help from my tutorial: Introduction to Direct3D which uses D3DX

- WitchLord

##### 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 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 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 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 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 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 on other sites
Nope. I trashed the DDraw and D3D code when I changed to D3DX.

##### Share on other sites
Here''s something new. It works fine in windowed mode. I only get the error when I try to run fullscreen. *frowns*
Does this shed any light on the problem?

##### 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 PASCALWinMain(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 on other sites
This may be a typo, but you link to "d3dx.lib" not "D3DXD.LIB"

+AA_970+

##### Share on other sites
Also, i don''t think you have to link to D3DIM.LIB when you used D3DX.

+AA_970+

##### 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 on other sites
This is really strange, anyway, i compiled the source code you posted and started up my game with it and it gave no problems.

+AA_970+

##### Share on other sites
This sounds very much like bug in either D3DX or in 3Dfx''s drivers. I think you are going to have to accept that and switch back to using D3DIM for the initialization instead.

- WitchLord

##### 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 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