Jump to content

  • Log In with Google      Sign In   
  • Create Account


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 lipsryme   Members   -  Reputation: 986

Like
0Likes
Like

Posted 07 April 2013 - 12:15 PM

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, 07 April 2013 - 12:16 PM.


Sponsor:

#2 LancerSolurus   Members   -  Reputation: 485

Like
0Likes
Like

Posted 07 April 2013 - 01:07 PM

Have you tried expanding it out and set x,y & z individually? I would suspect it would fix your problem.


******************************************************************************************
Youtube Channel


#3 MJP   Moderators   -  Reputation: 10235

Like
3Likes
Like

Posted 07 April 2013 - 01:13 PM

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, 07 April 2013 - 05:57 PM.


#4 Benny Stralberg   Members   -  Reputation: 892

Like
0Likes
Like

Posted 07 April 2013 - 01:14 PM

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.


-Benny-

#5 lipsryme   Members   -  Reputation: 986

Like
0Likes
Like

Posted 07 April 2013 - 01:17 PM

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, 07 April 2013 - 01:23 PM.


#6 AllEightUp   Moderators   -  Reputation: 4119

Like
0Likes
Like

Posted 07 April 2013 - 01:19 PM

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, 07 April 2013 - 01:19 PM.


#7 MJP   Moderators   -  Reputation: 10235

Like
1Likes
Like

Posted 07 April 2013 - 05:59 PM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS