Valid effects handle returning invalid technique handles

Started by
2 comments, last by Rectangle 11 years, 7 months ago
Please review the comments in the code below:
[source lang="cpp"]// The following code succesfully returns a valid effect handle without failure
ID3DXBuffer* piBuffer = NULL;
if(FAILED( D3DXCreateEffectFromFileA(m_d3dDev, m_szDefaultShaderFile, NULL, NULL, D3DXSHADER_DEBUG, NULL, &m_piDefaultEffect, &piBuffer) ))
{
if( piBuffer )
{
MessageBoxA(NULL, (LPCSTR)piBuffer->GetBufferPointer(), "HLSL", MB_OK);
piBuffer->Release();
}
return false;
}
if( piBuffer)
{
piBuffer->Release();
piBuffer = NULL;
}

// The following code succesfully returns the correct description data (6 params, 4 techs, 0 funcs)
D3DXEFFECT_DESC fxd;
m_piDefaultEffect->GetDesc(&fxd);

// The following code returns <Bad Ptr&gt, and any following use of this handle results in errors
D3DXHANDLE tech = m_piDefaultEffect->GetTechnique(1); // FAILS
tech = m_piDefaultEffect->GetCurrentTechnique(); // FAILS
m_piDefaultEffect->FindNextValidTechnique(NULL, &tech); // FAILS[/source]
Any idea why this could be happening? How can I fix this?
Advertisement
How many techniques are there in that effect file? Seems like there's only one and if that's true then you should pass 0 as an argument to GetTechnique to retrieve the first technique

How many techniques are there in that effect file? Seems like there's only one and if that's true then you should pass 0 as an argument to GetTechnique to retrieve the first technique


As stated in the comments of my previous post, GetDesc() returns 6 parameters, 4 techniques, and 0 functions.
No, GetTechnique(0) fails all the same as GetNextValidTechnique(NULL, NULL).
Here's the shader:
[source lang="cpp"]float4x4 WorldViewProjection : WORLDVIEWPROJECTION;
float4x4 World : WORLD;
float4x3 WorldInverseTranspose : WORLDINVERSETRANSPOSE;
float3 afLightColor[5];
float3 afLightDir[5];
float3 vCameraPos : CAMERAPOSITION;
struct VS_INPUT
{
float3 Position : POSITION;
float3 Normal : NORMAL;
};
struct VS_OUTPUT
{
float4 Position : POSITION;
float3 ViewDir : TEXCOORD0;
float3 Normal : TEXCOORD1;
};
VS_OUTPUT DefaultVShader(VS_INPUT IN)
{
VS_OUTPUT Out;
float3 objPos = IN.Position;
Out.Position = mul( float4( objPos, 1.0f), WorldViewProjection);
float3 WorldPos = mul( float4( objPos, 1.0f), World);
Out.ViewDir = vCameraPos - WorldPos;
Out.Normal = mul(IN.Normal, WorldInverseTranspose);
return Out;
}
float4 DefaultPShaderSpecular_D1(VS_OUTPUT IN) : COLOR0
{
float4 OUT = float4(0.0f, 0.0f, 0.0f, 1.0f);
float3 Normal = normalize(IN.Normal);
float3 ViewDir = normalize(IN.ViewDir);
{
float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;
float3 Reflect = reflect (Normal, afLightDir[0]);
float fHalfLambert = L1 * L1;
OUT.rgb += afLightColor[0] * (fHalfLambert + saturate(fHalfLambert * 4.0f) * pow(dot(Reflect, ViewDir), 9));
}
return OUT;
}
float4 DefaultPShaderSpecular_D2(VS_OUTPUT IN) : COLOR0
{
float4 OUT = float4(0.0f, 0.0f, 0.0f, 1.0f);
float3 Normal = normalize(IN.Normal);
float3 ViewDir = normalize(IN.ViewDir);
{
float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;
float3 Reflect = reflect (ViewDir, Normal);
float fHalfLambert = L1 * L1;
OUT.rgb += afLightColor[0] * (fHalfLambert + saturate(fHalfLambert * 4.0f) * pow(dot(Reflect, afLightDir[0]), 9));
}
{
float L1 = dot(Normal,afLightDir[1]) * 0.5f + 0.5f;
float3 Reflect = reflect (ViewDir,Normal);
float fHalfLambert = L1 * L1;
OUT.rgb += afLightColor[1] * (fHalfLambert + saturate(fHalfLambert * 4.0f) * pow(dot(Reflect,afLightDir[1]),9));
}
return OUT;
}
float4 DefaultPShaderSpecular_PS20_D1(VS_OUTPUT IN) : COLOR0
{
float4 OUT = float4(0.0f, 0.0f, 0.0f, 1.0f);
float3 Normal = normalize(IN.Normal);
float3 ViewDir = normalize(IN.ViewDir);
{
float L1 = dot(Normal,afLightDir[0]);
float3 Reflect = reflect (Normal,afLightDir[0]);
OUT.rgb += afLightColor[0] * ((L1) + pow(dot(Reflect,ViewDir),9));
}
return OUT;
}
float4 DefaultPShaderSpecular_PS20_D2(VS_OUTPUT IN) : COLOR0
{
float4 OUT = float4(0.0f, 0.0f, 0.0f, 1.0f);
float3 Normal = normalize(IN.Normal);
float3 ViewDir = normalize(IN.ViewDir);
{
float L1 = dot(Normal,afLightDir[0]);
float3 Reflect = reflect (Normal,afLightDir[0]);
OUT.rgb += afLightColor[0] * ((L1) + pow(dot(Reflect,ViewDir),9));
}
{
float L1 = dot(Normal,afLightDir[1]);
float3 Reflect = reflect (Normal,afLightDir[1]);
OUT.rgb += afLightColor[1] * ((L1) + pow(dot(Reflect,ViewDir),9));
}
return OUT;
}
technique DefaultFXSpecular_D1
{
pass p0
{
CullMode=none;
PixelShader = compile ps_3_0 DefaultPShaderSpecular_D1();
VertexShader = compile vs_3_0 DefaultVShader();
}
};
technique DefaultFXSpecular_D2
{
pass p0
{
CullMode=none;
PixelShader = compile ps_3_0 DefaultPShaderSpecular_D2();
VertexShader = compile vs_3_0 DefaultVShader();
}
};
technique DefaultFXSpecular_PS20_D1
{
pass p0
{
CullMode=none;
PixelShader = compile ps_2_0 DefaultPShaderSpecular_PS20_D1();
VertexShader = compile vs_2_0 DefaultVShader();
}
};
technique DefaultFXSpecular_PS20_D2
{
pass p0
{
CullMode=none;
PixelShader = compile ps_2_0 DefaultPShaderSpecular_PS20_D2();
VertexShader = compile vs_2_0 DefaultVShader();
}
};[/source]
Well after a lot of searching, I came across this post: http://www.gamedev.net/topic/400760-efffects-and-bad-ptr/

Turns out, it's supposed to be a <bad ptr>? Either way, passing the handle into SetTechnique() seems to return S_OK, so I can assume that all is well afterall.

This topic is closed to new replies.

Advertisement