• 13
• 16
• 27
• 9
• 9

# [SlimDX] strange error from Effect.FromFile (D3D9)

This topic is 3354 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, i've just started toying around with HLSL/shaders in SlimDX/Direct3D9, so please forgive me if i missed something totaly obvious. But i can't seem to even get the most basic shaders running. Thats how i try to create the effect:
fx = Effect.FromFile( GraphicsDevice, "Content\\Effects\\Test.fx", ShaderFlags.None );


this line always throws a Direct3D9Exception "E_FAIL: An undetermined error occurred (-2147467259)". GraphicsDevice is a valid Direct3D9.Device (i use it just above that line to create a VertexBuffer without any trouble), the file is there (opening and dumping to console works like expected) and the shader seems to be ok (compiles and runs in fx composer) and i tried different types/combinations of shader flags (i.e. ShaderFlag.Debug | ShaderFlags.PartialPrecision like in the water sample that comes with SlimDX). I'm using the November 2008 distribution of SlimDX, the samples work, even those that use effects like the water sample. I also tried the debug runtimes + unmanaged code debugging but that only gives the usual infos when the device is created. No extra details or actually nothing at all about that error. What am i missing here? Thanks. Edit: if that helps, here's the shader:
float4x4 ProjectionMatrix : PROJECTION;
float4x4 ViewMatrix : VIEW;
float4x4 WorldMatrix : WORLD;

float4 LightDirection;
float4 LightAmbient;
float4 LightColor;

struct VertexIn {
float3 Position : POSITION;
float3 Normal : NORMAL;
};

struct VertexOut {
float4 Position : POSITION0;
float3 Normal : TEXCOORD0;
float3 LightDir : TEXCOORD1;
};

void VS_Main( VertexIn input, out VertexOut output ) {
float4x4 WorldViewProjectionMatrix = mul( WorldMatrix, mul( ViewMatrix, ProjectionMatrix ) );
float3 LightDir = normalize( LightDirection );

output.Position = mul( float4( input.Position, 1 ), WorldViewProjectionMatrix );
output.Normal = normalize( mul( input.Normal, WorldMatrix ) );
output.LightDir = LightDir;
}

float4 PS_Main( float3 Normal : TEXCOORD0, float3 LightDir : TEXCOORD1 ) : COLOR0 {
return LightAmbient + LightColor * saturate( dot( LightDir, Normal ) );
}

technique Test {
pass P0 {
}
}


but as i said: it compiles, runs and works in fx composer so shouldn't be the problem.

##### Share on other sites
Enable the debug runtimes, use unmanaged debugging, and call the overload of FromFile that takes "out compilationError" to examine any messages from the compiler.

Post the results -- particularly of any additional messages printed to the output window.

##### Share on other sites
Well, first of all thanks for the quick reply!
The Effect.FromFile overload that returns an error message did the trick. I was already using the debug runtimes and unmanaged code debugging, but that didn't give any error messages.
I fell kinda dumb but in the end the problem was, that i created the shaders as text files in Visual Studio which uses UTF-8 encoding by default. Converted it to ASCII and it worked. Well, [rolleyes].

##### Share on other sites
Yeah, the dumb effect compiler barfs on Unicode, which is really annoying. We should try to get an exception thrown if we can detect that the file is Unicode.

As a side note, you don't necessarily need to use the overload that returns compiler errors if you don't want to. The exception that gets thrown on failure contains the compiler errors inside its Data property, so you can look at that in the debugger.

##### Share on other sites
Quote:
 Original post by Mike.PopoloskiWe should try to get an exception thrown if we can detect that the file is Unicode.
You don't really want to go there. There's a Win32 API function that attempts to detect encoding, but it's not completely reliable.

##### Share on other sites
Quote:
 The exception that gets thrown on failure contains the compiler errors inside its Data property, so you can look at that in the debugger.

The Data property is the spawn of Satan and I, for one, will not condone its use!

##### Share on other sites
While i also don't think that those methods should check the encoding of it's input, it would imho help a lot if the exception thrown when effect compiler fails to compile it's input would be a little bit more descriptive.