2

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.

Fattie
  • 27,874
  • 70
  • 431
  • 719
lolollo
  • 48
  • 9
  • Thanks for the pointers, said the engineer. Yes i meant PoseProvider, and it looks like it could be an IDE issue (i have never used C#, but in Java similar things would work), but since there was nothing on Google about it and i started from a clean install of everything it was strange – lolollo Jul 03 '16 at 15:32

1 Answers1

2

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.)

Fattie
  • 27,874
  • 70
  • 431
  • 719
  • i'll be trying the spaces trick soon, but as you said my code and the original do differ, since mine is sure to call both functions preventing variables from being unassigned. It is strange that there are a thousand download from Tango apps if the original code had unity-independent issues. Thank you – lolollo Jul 03 '16 at 17:59
  • I'm sorry I have no more specific info! regarding the 1000 downloads. 99% of unity users are new hobbyists, no clue :-) – Fattie Jul 03 '16 at 19:57