• Advertisement
Sign in to follow this  

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

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

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
Advertisement

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
Guest Hiwas

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 Hiwas

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
Sign in to follow this  

  • Advertisement