Sign in to follow this  
lipsryme

error X4000: Use of potentially uninitialized variable (How to fix?)

Recommended Posts

Assuming a function that looks kind of like this:

 

bool Test(in float x, in float3 cameraPosition)
{
  float3 l = float3(cameraPosition.x, cameraPosition.y + 10.0f, cameraPosition.z);

  if(l.x <= 0.5f)
  {
    //...
    return true;
  }
  else
  {
    //...
    return true;
  }

  return false;
}

 

This will print a warning saying: "error X4000: Use of potentially uninitialized variable" at the exact line of the if condition.

In this situation how would I avoid the warning ? I've tried several things like giving it a default value but it just doesn't work.

Any ideas ?

Edited by lipsryme

Share this post


Link to post
Share on other sites

I have occasionally run into an issue with the HLSL compiler where it will falsely emit that error when I use mid-function return statements. Usually I would just re-write the function to take out the return statements and the error would go away.

Edited by MJP

Share this post


Link to post
Share on other sites

I had this error the other day and solved it by removing the D3DCOMPILE_SKIP_OPTIMIZATION flag from my call to D3DCompile2. I have no idea why it solved it but it did.

Share this post


Link to post
Share on other sites

I've tried setting them individually, didn't work.

 

@MJP you mean something like this ?:

UPDATE: Yep that works happy.png  thanks.

bool result = false;

if(x <= y)
{
  result = true;
}
else
{
   result = false;
}


return result;
Edited by lipsryme

Share this post


Link to post
Share on other sites

I have occasionally run into an issue with the HLSL compiler where it will falsely emit that error when I use mid-function return statements. Usually I would just we-write the function to take out the return statements and the error would go away.

Oh noes, Elmer Fudd has invaded GameDev.net!!!!!  (see above "we-write")

 

Sorry, just couldn't resist........... smile.png

Edited by AllEightUp

Share this post


Link to post
Share on other sites

I have occasionally run into an issue with the HLSL compiler where it will falsely emit that error when I use mid-function return statements. Usually I would just we-write the function to take out the return statements and the error would go away.

Oh noes, Elmer Fudd has invaded GameDev.net!!!!!  (see above "we-write")

 

Sorry, just couldn't resist........... smile.png

 

Be quiet, I'm busy hunting wabbits.

Share this post


Link to post
Share on other sites

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