Jump to content
  • Advertisement
Sign in to follow this  
Aqua Costa

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

This topic is 2850 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!