Search Unity

variable 'o' used without having been completely initial (d3d9) 68

Discussion in 'Shaders' started by Handsome-Wisely, Feb 5, 2016.

  1. Handsome-Wisely

    Handsome-Wisely

    Joined:
    Mar 20, 2013
    Posts:
    102
    my many shader (download from net) find a error like this:

    variable 'o' used without having been completely initial (d3d9) 68

    and in shader like this:

    Code (CSharp):
    1.  
    2. v2f vert (appdata_img v)
    3.             {
    4.                 v2f o;
    5.                 o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
    6.                 #ifdef SOFTPARTICLES_ON
    7.                 o.projPos = ComputeScreenPos (o.vertex);
    8.                 COMPUTE_EYEDEPTH(o.projPos.z);
    9.                 #endif
    10.                 o.texcoord = TRANSFORM_TEX(v.texcoord.xy, _MainTex);
    11.                 return o;
    12.             }
    13.  
    i think may be my 5.3 make this error.
    please tell me how to init this 'o' completely!

    thanks very much.
     
  2. kru

    kru

    Joined:
    Jan 19, 2013
    Posts:
    452
    That error indicates that your method is failing to write a value to each field of your v2f struct when compiling the shader for d3d9. You need to make sure that each field of 'o' has a value before your return it.
     
  3. smd863

    smd863

    Joined:
    Jan 26, 2014
    Posts:
    292
    Unity actually has a shortcut that will do this for you. If you look in some of the includes for the standard shader you will find:

    Code (csharp):
    1.  
    2. VertexOutputForwardBase o;
    3. UNITY_INITIALIZE_OUTPUT(VertexOutputForwardBase, o);
    4.  
    That should initialize everything to 0; I believe it resolves to "name = (type)0" on platforms that need it. You should be able to use that as well (i.e. "UNITY_INITIALIZE_OUTPUT(v2f, o);") anywhere you are getting this error.