Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Studio Chat / 3D object info sometimes returns "nan" or "-nan(ind)"

Author
Message
Zappo
Valued Member
19
Years of Service
User Offline
Joined: 27th Oct 2004
Location: In the post
Posted: 8th Apr 2023 20:06
I've created an app which loads a 3D object and applies simple dynamic physics to it. Most of the time it works exactly as expected, but occasionally the 3D object just seems to not appear. Reading any of it's details (X,Y,Z position, X,Y,Z angle) comes back as "nan" or "-nan(ind)", i.e. not a number. The object still exists if you test for it (GetObjectExists) and everything else in the loop seems to carry on running fine but that object is just not visible.

Is there a way in AppGameKit Studio Tier 1 to detect if a float value comes back as NaN? I've tried testing it against 0, I've tried converting it to a string (Str), I've even tried converting it to a string and then back to a float for comparison. It is obviously an error as a floating point number can never be NaN but the app just continues as if nothing is wrong and I cannot detect it to try reloading the 3D object.

Any thoughts?
Posting my code isn't really an option as the problem is so intermittent. Sometimes it will work once and then break. Sometimes it will work 100 times before breaking.
Zappo
Valued Member
19
Years of Service
User Offline
Joined: 27th Oct 2004
Location: In the post
Posted: 8th Apr 2023 20:17
Okay. Sorry for the double post but as soon as I posted my question, I thought of a possible test. Isn't that always the way?

There is an old trick to test for NaN which is basically:

By testing the value against itself, this statement returns true if the result is not-a-number and false if it is a number.

It doesn't explain why it seems to break randomly in the first place but at least I can test for it now.
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 9th Apr 2023 02:06 Edited at: 9th Apr 2023 02:16
Quote: "I've created an app which loads a 3D object and applies simple dynamic physics to it."

is that all it does so far?

if you should go on to delete the 3D object (as i suspect you might) without also deleting the physics body as well, i wonder if this issue might be in play somehow.

namely: "DeleteObject() doesn't Delete3DPhysicsBody()" where both would have the same ID/cross-reference eachother somewhere/somehow?
Zappo
Valued Member
19
Years of Service
User Offline
Joined: 27th Oct 2004
Location: In the post
Posted: 10th Apr 2023 00:48
Thanks for the link Virtual Nomad. The app does everything inside a game loop so once finished, it removes the physics body of the dynamic object and then deletes it's 3D object before starting over. I even tried adding Reset3DPhysicsWorld() and setting up the whole physics world again on each new game, but that didn't helped either.

After commenting out all of the physics code and introducing them back line by line I have found the problem. I wanted to introduce a little random nudge to the object after creating it by using the linear velocity command like so:

If the X, Y and Z direction properties of the linear velocity are all zero (which randomly can happen in this case) then it tries to apply a force but doesn't know which direction to apply it - and it breaks the object. By changing that line so it always has a direction to push the object, it works and hasn't broken since. I just left it running through 100's of iterations and it's behaved itself perfectly.

I'm not sure if this should be classed as a bug, or just programmer error (me) so I haven't added it to GitHub yet. I suppose in an ideal world it should catch this mistake and not just break the object, so let me know if you think I should add it as a bug.
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 10th Apr 2023 07:41 Edited at: 10th Apr 2023 07:59
nah, that's a bug. it should simply stop if vel = 0,0,0 (and i tested 0 and <> 0 for initial speed) and gravity should do its thing.

play with the 2 "rem me" lines, as well. what do you make of -nan(ind) ?

and same occurs with SetObject3DPhysicsAngularVelocity(Obj,0,0,0,0).

btw, the fixcamera was part of me trying to follow the object into oblivion (i had the skybox active, etc).

meanwhile, bug posted.

just tried replacing case 1: with SetObject3DPhysicsLinearVelocity(box,10,0,10,0) and it generates yvelocity (which caps at -1200.0).
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 10th Apr 2023 08:10
btw, the solid bug work/reporting on the repo is appreciated

Login to post a reply

Server time is: 2024-04-18 10:05:30
Your offset time is: 2024-04-18 10:05:30