Center bug...

Report bugs, bug fixes and workarounds here.
Topic author
Kendrix
Posts: 159
Joined: 02.06.2002
With us: 22 years 5 months
Location: near Paris, France
Contact:

Center bug...

Post #1by Kendrix » 30.11.2003, 17:05

Hi,

I've just updated my CVS (not done since 2 months) and now I got a new bug.

If i'm already centered on a body and I press the "c" key again : the camera jerks and finally returns to the center of the body...

But it should not move at all (like before) since it's already centered...

And in e more general way, the center command now moves the camera really strangly...

Avatar
selden
Developer
Posts: 10192
Joined: 04.09.2002
With us: 22 years 2 months
Location: NY, USA

Post #2by selden » 30.11.2003, 17:59

Are you using Capital C (shift-c) or lower-case c?

Capital C is new: it is supposed to keep the previously selected object in the same position on the screen while the newly selected object is centered. (e.g. it can be used to keep a spacecraft in view while turning the viewpoint toward the next flyby target.)

Lower-case c is supposed to work as it always has: it should just turn the viewpoint toward the currently selected object.

Is this what is happening or is it doing something different?
Selden

Topic author
Kendrix
Posts: 159
Joined: 02.06.2002
With us: 22 years 5 months
Location: near Paris, France
Contact:

Post #3by Kendrix » 01.12.2003, 00:11

I know the differences between the "C" and the "c" command.

Until now they worked very well !

But the simple "center" command is bugged since I've updated my CVS tree (today and not done since end of september)

Just read the exemple I gave in the first post to have a description of the bug.

Another example : I was centered on earth and I press "c" again : Suddenly I was seeing only black everywhere and I was at 18 million LY from the earth !!!

What a bug !

chris
Site Admin
Posts: 4211
Joined: 28.01.2002
With us: 22 years 9 months
Location: Seattle, Washington, USA

Post #4by chris » 01.12.2003, 01:26

I don't see this bug . . . Which compiler are you using? It's possible that there's a divide by zero error someplace that only appears when a particular compiler or library is used.

--Chris

Topic author
Kendrix
Posts: 159
Joined: 02.06.2002
With us: 22 years 5 months
Location: near Paris, France
Contact:

Post #5by Kendrix » 01.12.2003, 06:57

Yes I forgot to tell you that now I'm compiling under .NET and not 6.0 anymore...

chris
Site Admin
Posts: 4211
Joined: 28.01.2002
With us: 22 years 9 months
Location: Seattle, Washington, USA

Post #6by chris » 01.12.2003, 08:03

Kendrix wrote:Yes I forgot to tell you that now I'm compiling under .NET and not 6.0 anymore...


That's what I thought . . . I ran into an earlier divide by zero problem that only appeared when I compiled with .NET. This would be easy for me to debug except that the hard drive just died on my computer with Visual Studio .NET installed. I'm reluctant to update my only other Windows machine with .NET at the moment, but I should be getting a new drive very soon.

--Chris

Topic author
Kendrix
Posts: 159
Joined: 02.06.2002
With us: 22 years 5 months
Location: near Paris, France
Contact:

Post #7by Kendrix » 01.12.2003, 12:41

Perhaps you could tell me where to investigate these divisions so I can debug...

Harry
Posts: 559
Joined: 05.09.2003
With us: 21 years 2 months
Location: Germany

Post #8by Harry » 01.12.2003, 12:42

chris wrote:That's what I thought . . . I ran into an earlier divide by zero problem that only appeared when I compiled with .NET.


Just saw the same (or at least a similar) problem on my system (Linux, gcc 3.2): Pressing "c" two times quickly in succession (i.e. while first still shows "travelling") leads to this:
Image

Pressing "g" will decrease the displayed distance like with normal goto, but will reset to 3718 ly after travelling.

UPDATE:
This also happens with goto. Sometimes I can't trigger the bug, other times it happens the first time I press "c" (or "g") twice in rapid succession. The "follow" mode seems to be immune, but this could be luck & my imagination.

Chris, after the bug occurs, the rotation is w=x=y=z=NAN. Could this be the result of calling normalize on a all-zero quat?


Harald

Harry
Posts: 559
Joined: 05.09.2003
With us: 21 years 2 months
Location: Germany

Post #9by Harry » 03.12.2003, 14:53

Harry wrote:Chris, after the bug occurs, the rotation is w=x=y=z=NAN. Could this be the result of calling normalize on a all-zero quat?


It's not...

The problem lies in quaternion.h Quaternion::slerp() (l. 581):

Code: Select all

template<class T> Quaternion<T> Quaternion<T>::slerp(Quaternion<T> q0,
                                                     Quaternion<T> q1,
                                                     T t)
{
    T c = dot(q0, q1);
    T angle = (T) acos(c);
    if (abs(angle) < (T) 1.0e-5)
        return q0;
...


If q0 and q1 are nearly equal, c = dot(q0, q1) can become > 1 8O (in my case: the lsb of c is set, which it shouldn't be)! Don't know how this is happening, this may be a compiler thing or simply bad luck with rounding. Whatever, the result is:
angle will be NaN, then "s" and "is" will be NaN too and the result is all NaNs.

Chris, can we have a guard against this one? Like checking for "c > 1.0f", or making sure dot() never returns any result > 1 ? Or maybe inverting the "if (abs(angle) < (T) 1.0e-5)", AFAIR comparisons with NaN always fail...

I hope there aren't more arithmetic bugs like this one. They are hard to evade, as the code seems to be ok (it actually is, from a mathematical point of view).

Harald

chris
Site Admin
Posts: 4211
Joined: 28.01.2002
With us: 22 years 9 months
Location: Seattle, Washington, USA

Post #10by chris » 03.12.2003, 23:48

Harry wrote:The problem lies in quaternion.h Quaternion::slerp() (l. 581):

Code: Select all

template<class T> Quaternion<T> Quaternion<T>::slerp(Quaternion<T> q0,
                                                     Quaternion<T> q1,
                                                     T t)
{
    T c = dot(q0, q1);
    T angle = (T) acos(c);
    if (abs(angle) < (T) 1.0e-5)
        return q0;
...


Yes, this looks like the problem . . . In cases like this, the input to acos needs to be clamped to [ -1, 1 ]

Chris, can we have a guard against this one? Like checking for "c > 1.0f", or making sure dot() never returns any result > 1 ? Or maybe inverting the "if (abs(angle) < (T) 1.0e-5)", AFAIR comparisons with NaN always fail...

The test should be:

Code: Select all

if (c > (T) 1.0)
    c = (T) 1.0;
else if (c < (T) -1.0)
    c = (T) -1.0;


It would be inappopriate to modify dot() to clamp its result, as there's no mathematical limit to the range of this function.

--Chris

Harry
Posts: 559
Joined: 05.09.2003
With us: 21 years 2 months
Location: Germany

Post #11by Harry » 04.12.2003, 01:43

chris wrote:It would be inappopriate to modify dot() to clamp its result, as there's no mathematical limit to the range of this function.


Ups :oops: I must have been thinking about normalized vectors...

Topic author
Kendrix
Posts: 159
Joined: 02.06.2002
With us: 22 years 5 months
Location: near Paris, France
Contact:

Post #12by Kendrix » 05.12.2003, 15:17

I've added the clamping and it does not change anything :cry:

Topic author
Kendrix
Posts: 159
Joined: 02.06.2002
With us: 22 years 5 months
Location: near Paris, France
Contact:

Post #13by Kendrix » 09.12.2003, 13:35

By the way, If I compile in DEBUG there is no probleme at all with the center function.

So the problem comes from the RELEASE version only !

Harry
Posts: 559
Joined: 05.09.2003
With us: 21 years 2 months
Location: Germany

Post #14by Harry » 09.12.2003, 14:33

WFM - I can't trigger this bug anymore. But considering the type of bug there could be many places possibly affected. Maybe replacing calls to acos (and similar functions) by a safe wrapper could help, at least for debugging.

Topic author
Kendrix
Posts: 159
Joined: 02.06.2002
With us: 22 years 5 months
Location: near Paris, France
Contact:

Post #15by Kendrix » 09.12.2003, 17:08

If I remove the "maximize speed" in the optimisation panel of the projects properties the bug is gone...

So it seems that .NET does some bad optimisations !


Return to “Bugs”