Jump to content

  • Log In with Google      Sign In   
  • Create Account


D3DCreateEffectFromMemory Fails, everything is correct, why?

  • You cannot reply to this topic
6 replies to this topic

#1 VanillaSnake   Members   -  Reputation: 119

Like
0Likes
Like

Posted Yesterday, 12:04 AM

Hi, I'm trying to use a simple hlsl file in the rendering, so I compile my .fx with the fxc.exe as directed on msdn, it produces a clean object with no errors. I read it into memory using msdn's method, but for some reason this function still comes back with E_FAIL. Here's some of my code:

 

ifstream is(TEXT("DX10RendererEffect.fxo"), ios::binary);

is.seekg(0, ios_base::end);

streampos pos = is.tellg();

is.seekg(0, ios_base::beg);

char * effectBuffer = new char[pos];

is.read(effectBuffer, pos);

HRESULT hr;

if (FAILED(hr = D3D10CreateEffectFromMemory((void*)effectBuffer, pos, 0, softObjPtr->pD3D10Device, NULL, &softObjPtr->pD3D10Effect))){

return;
}

 

Also, I've created my device using the D3D10DEBUG_DEVICE flag (something like that), but the function doesn't say anything besides E_FAIL, that on msdn says that means the debug layer is not installed.

 

I don't know if this matters but I'm on a fresh in stall of Windows 7 and I just installed Windows 8.1 SDK. It's a hassle because all the D3DX helper functions are removed, so I can't compile from file, and must use a build rule on visual studio to compile my fx files manually. And the D3D sdk is completely merged with Windows SDK, so I can't tell if the debug layer was installed or not, it should have been right? Any suggestions?


You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts

 

Time flies like an arrow; fruit flies like a banana. - Old Wise Eastern tribesman saying


Sponsor:

#2 L. Spiro   Crossbones+   -  Reputation: 12274

Like
3Likes
Like

Posted Yesterday, 12:13 AM

You don’t release effectBuffer on failure, which is a memory leak.

Did you compile the effect with the correct version?
Did you verify that it compiled correctly?
Did you verify that the file exists?
Did you add your program to the debug-layer list of executables and enable debugging of it?


L. Spiro
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#3 VanillaSnake   Members   -  Reputation: 119

Like
0Likes
Like

Posted Yesterday, 12:29 AM

You don’t release effectBuffer on failure, which is a memory leak.

Did you compile the effect with the correct version?
Did you verify that it compiled correctly?
Did you verify that the file exists?
Did you add your program to the debug-layer list of executables and enable debugging of it?


L. Spiro

 

I'm trying to get it to work, so memory leaks are second priority right now. 

Here is my compilation string in the build tool:

 

"C:\Program Files (x86)\Windows Kits\8.1\bin\x86\fxc.exe" /Od /Zi /T fx_4_0 /Fo "C:\Users\Tim\Documents\Visual Studio Projects\SoftwareRasterizer\DX10RendererEffect.fxo" "C:\Users\Tim\Documents\Visual Studio Projects\SoftwareRasterizer\DX10RendererEffect.fx"

 

this is the end of my .fx file

technique10 Render{pass P0{SetVertexShader(CompileShader(vs_4_0, VS()));SetGeometryShader(NULL);SetPixelShader(CompileShader(ps_4_0, PS()));}}
So the versions seem to match.
 
When I compile it in VS I get this: 
 
CUSTOMBUILD : warning X4717: Effects deprecated for D3DCompiler_47
1>  
1>  compilation object save succeeded; see C:\Users\Tim\Documents\Visual Studio Projects\SoftwareRasterizer\DX10RendererEffect.fxo
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
 
The file does exist and I do check it, I just wrote that little file reading snippet on the fly, my actual function is
 
int LoadFileToMemory(const wchar_t* szFileName, char** buffer){ifstream inFile(szFileName, ios::binary); if (!inFile.good()) //file not foundreturn -1; streampos beginPos = inFile.tellg();inFile.seekg(0, ios::end);streampos endPos = inFile.tellg();int size = endPos - beginPos; (*buffer) = new char[size];inFile.read((*buffer), size);inFile.close(); return size;}

 

I'm not sure how to add the program to the dubug layer though, that might be helpful if it gives me a more elaborate fail string. How exactly do I do that?


You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts

 

Time flies like an arrow; fruit flies like a banana. - Old Wise Eastern tribesman saying


#4 cozzie   Members   -  Reputation: 1468

Like
1Likes
Like

Posted Yesterday, 05:48 AM

Can you try to retrieve the HRESULT error string?

 

Something like this:
 

void PrintDebugOutput(const LPCWSTR pText, const HRESULT pHr)
{
	OutputDebugString(pText);
	OutputDebugString(DXGetErrorString(pHr));
	OutputDebugString(L", ");
	OutputDebugString(DXGetErrorDescription(pHr));
	OutputDebugString(L"\n");
}


#5 VanillaSnake   Members   -  Reputation: 119

Like
0Likes
Like

Posted Yesterday, 07:46 PM

Can you try to retrieve the HRESULT error string?
 
Something like this:
 

void PrintDebugOutput(const LPCWSTR pText, const HRESULT pHr)
{
	OutputDebugString(pText);
	OutputDebugString(DXGetErrorString(pHr));
	OutputDebugString(L", ");
	OutputDebugString(DXGetErrorDescription(pHr));
	OutputDebugString(L"\n");
}

 
So I get "E_FAIL" out geterrorstring
and "An undetermined error occurred" at the errordescription
 
Another thing is that I installed the wrong SDK originally. I got the windows 8.1 sdk, even though I'm on windows 7. I'm not sure if it's a big deal but just to be safe I uninstalled the windows 8.1 sdk and installed windows 7.1 instead, along with June 2010 DirectX SDK. Otherwise the above function you suggested doesn't even exist as windows 8 merged dx with the os, so you have to use the regular os error reporting function. Anyways with that taken care of, it's the same issue and I STILL can't get DX to spit out debug information. What am I doing wrong??? This is how I create my device:

 

if (FAILED(D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, D3D10_CREATE_DEVICE_DEBUG, D3D10_SDK_VERSION, &softObjPtr->D3D10SwapChainDesc, &softObjPtr->pD3D10SwapChain, &softObjPtr->pD3D10Device)))

{

ZeroMemory(&softObjPtr->D3D10SwapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));

return;

}

 

I also selected the program "SoftwareRasterizer" in my debug folder as the target in the DX Control Panel, should I instead select the VS 2012 executable? 

 

I'm trying to move my direct draw rasterizer to DX10 and this is proving to be quite a hassle, lol.

 

I'm going to try using the old DX functions to compile my effect instead of the FXC and I'll update on how it goes, but I would still appreciate the help in trying to get my debug output to work ))


You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts

 

Time flies like an arrow; fruit flies like a banana. - Old Wise Eastern tribesman saying


#6 VanillaSnake   Members   -  Reputation: 119

Like
0Likes
Like

Posted Yesterday, 09:56 PM

OK so rewrote the code with D3DX10CreateEffectFromFile and it seems to work, so I'm thinking something was off about the object created by fxc compiler, judging from another forum where someone had a similar issue it pads the size of the file, but not sure, it was a post from 2008. Thanks for the help.


You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts

 

Time flies like an arrow; fruit flies like a banana. - Old Wise Eastern tribesman saying


#7 cozzie   Members   -  Reputation: 1468

Like
0Likes
Like

Posted Today, 01:27 AM

Good to hear it's working now, good luck on your project





PARTNERS