Sign in to follow this  

[DirectX 10] Game throws exception when I update Effect variable

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

In my shader I have this constant buffer:

cbuffer cbPerFrame
{
float3 gEyePosW;
float4x4 gInvViewProj;
}



In my app code I load the vars like this:

ID3D10EffectVariable* lightBEyePosVar;
ID3D10EffectMatrixVariable* lightBInvViewProjVar;

[...]

lightBEyePosVar = LightBufferFX->GetVariableByName("gEyePosW");
lightBInvViewProjVar = LightBufferFX->GetVariableByName("gInvViewProj")->AsMatrix();



And I updated them like this:

lightBEyePosVar->SetRawValue(&(getCamera().getPosition()), 0, sizeof(D3DXVECTOR3));
lightBInvViewProjVar->SetMatrix((float*)&invViewProj);
lightBNormalMapVar->SetResource(mNormalMapRV);
lightBDepthMapVar->SetResource(mDepthMapRV);



The strange thing is that in the first frame everything works correctly, but in the second the lightBEyePosVar and lightBInvViewProjVar vars loose its values and when I try to set the value an exception is thrown... But the lightBNormalMapVar and lightBDepthMapVar vars work correctly...

Any idea of what is causing this?

Share this post


Link to post
Share on other sites
Quote:
Original post by Aqua Costa
The strange thing is that in the first frame everything works correctly, but in the second the lightBEyePosVar and lightBInvViewProjVar vars loose its values and when I try to set the value an exception is thrown... But the lightBNormalMapVar and lightBDepthMapVar vars work correctly...


What do you mean by "lose its values"? Do you mean the actual address stored in the pointer variable gets changed? If that's the case, you can just set a data breakpoint on the address of the pointer variable and VS will break when it gets modified.

Share this post


Link to post
Share on other sites
Quote:
Original post by MJP
Quote:
Original post by Aqua Costa
The strange thing is that in the first frame everything works correctly, but in the second the lightBEyePosVar and lightBInvViewProjVar vars loose its values and when I try to set the value an exception is thrown... But the lightBNormalMapVar and lightBDepthMapVar vars work correctly...


What do you mean by "lose its values"? Do you mean the actual address stored in the pointer variable gets changed? If that's the case, you can just set a data breakpoint on the address of the pointer variable and VS will break when it gets modified.


Well, the address stored in the pointer doesnt get changed...The value that gets changed is a var inside the lightBEyePosVar called _vfptr (check image above). I added a data breakpoint but when the value changed VS showed a "no source available" page.
Then I set a watch to the variable and I found that it changed before the Apply() function of technique that the lightBEyePosVar is related to is called.

Some more code:

Effects::lightBEyePosVar->SetRawValue(&(getCamera().getPosition()), 0, sizeof(D3DXVECTOR3)); <<<---- Everything ok when this method is called
Effects::lightBNormalMapVar->SetResource(mNormalMapRV);
Effects::lightBDepthMapVar->SetResource(mDepthMapRV);
Effects::lightBInvViewProjVar->SetMatrix((float*)&invViewProj); <<<---- Everything ok when this method is called

for(UINT x = 0; x < lights.size(); x++)
{
Effects::lightBLightVar->SetRawValue(&lights.at(x), 0, sizeof(Light));
Effects::lightBLightTypeVar->SetRawValue(&lights.at(x).type, 0, sizeof(Light));

Effects::lightBTech->GetPassByIndex(0)->Apply(0); <<<<---- Right before this method is called lightBNormalMapVar and lightBInvViewProjVar _pfptr values get changed to strange values...

UINT stride = sizeof(PosTexCVertex);
UINT offset = 0;
d3dDevice->IASetVertexBuffers(0, 1, &VB, &stride, &offset);
d3dDevice->IASetIndexBuffer(IB, DXGI_FORMAT_R32_UINT, 0);
d3dDevice->DrawIndexed(6, 0, 0);
}
[/source


[Edited by - Aqua Costa on December 30, 2010 4:18:15 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Aqua Costa
Well, the address stored in the pointer doesnt get changed...The value that gets changed is a var inside the lightBEyePosVar called _vfptr (check image above). I added a data breakpoint but when the value changed VS showed a "no source available" page.


Did you still get a call stack? You should be able to trace back to find out which function was called in your code.

Share this post


Link to post
Share on other sites
Well, I fixed it.
It was a simple mistake in this line:
Effects::lightBLightTypeVar->SetRawValue(&lights.at(x).type, 0, sizeof(Light));

lights.at(x).type is a int value so it should be sizeof(int) instead of sizeof(Light)...

Thanks to everyone anyway... :D

Share this post


Link to post
Share on other sites

This topic is 2544 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this