Search code examples
c#unity-game-enginemonogoogle-project-tango

PoseProvider.cs and Tango: MonoDevelop error


In TangoSDK/Core/Scripts/TangoWrappers/PoseProvider.cs, there are two variables who have problems when pressing Play on MonoDevelop in Unity:adjustedTimeStamp2 and targetToDevice. MonoDevelop complains about "Use of unassigned local variable", probably because it checks only the first part of that if.

I replaced line 104 and 105 from:

if (!GetFrameToDeviceTransformation(framePair.baseFrame,timeStamp, out adjustedTimeStamp1, out baseToDevice)
|| !GetFrameToDeviceTransformation(framePair.targetFrame, timeStamp, out adjustedTimeStamp2, out targetToDevice))

with equivalent code:

        bool a = !GetFrameToDeviceTransformation(framePair.baseFrame, timeStamp, out adjustedTimeStamp1, out baseToDevice);
        bool b = !GetFrameToDeviceTransformation(framePair.targetFrame, timeStamp, out adjustedTimeStamp2, out targetToDevice);
        if (a||b)
        {
            pairIsValid = false;
        }

and now monodevelop doesn't complain anymore.

I'd like to know if it was only me, or if there are some things i should have activated on the editor to let it understand it.


Solution

  • Funny thing you mention this issue, I've noticed exactly the same problem with statements involving || and ! in Unity's version of Mono/c#.

    I am actually inclined to say on this question, it's just a known issue with Unity.

    As a cusiotisy you might try inserting more or less spaces / newlines, say

    if (
     ! GetFrameToDeviceTransformation(...)
     ||
     ! GetFrameToDeviceTransformation(...)
     )
    

    you might also try this, say ...

    if (
     ( ! GetFrameToDeviceTransformation(...) )
     ||
     ( ! GetFrameToDeviceTransformation(...) )
     )
    

    BTW I'm sure you're aware of this: your replacement code is very slightly different in behavior. Your code WILL run both the calls. The original code will not run the second call if the first one is false .. err .. true (you get what I mean!)

    So, to be anal, what about...

    bool finalCondition = false;
    bool a = !GetFrameToDeviceTransformation(...);
    if (a == true)
     {
     finalCondition = true;
     }
    else
     {
     bool b = !GetFrameToDeviceTransformation(...);
     if (b == true)
      {
      finalCondition = true;
      }
     }
    if (finalCondition)
     {
     pair whatever...
     }
    

    Also finally note

    I have no clue what GetFrameToDeviceTransformation does but it's entirely possible there is some sort of complex hardware racetrack condition going on. So, it might be that at Google's office, the sample code worked fine, but the engineers f'ed up and in fact it only randomly worked due to the hardware set; you're finding it doesn't work. (TBC if this is the case, what I say in the first sentence here, is irrelevant.)