Curtis L.Olson writes:
>
>Norman Vine writes:
>> another problem is in simgear / sky / cloud.cxx
>>
>> bool SGCloudLayer::reposition( sgVec3 p, sgVec3 up, double
>lon, double lat,
>>                             double alt )
>> {
>> ....
>>     // now calculate update texture coordinates
>>     if ( last_lon < -900 ) {
>>              cout << "last_lon < -900" << endl;
>>              last_lon = lon;
>>              last_lat = lat;
>>     }
>>     // change  if( lon - lat_lon != 0 || lat-last_lat != 0 )  to
>>     if ( fabs(lon-last_lon) > FLT_EPSILON || fabs(lat-last_lat) >
>> FLT_EPSILON ) {
>> ...
>> }
>
>Norman, can you provide any further information as to how this change
>eliminates problems on the windows side?

when there is no change there is a floating point exception in
calc_gc_course_dist().  I tied this with both the original and the
optimized versions.

>I understand that in general with floating point compares you want to
>test if the absolute value of the difference is < some epsilon,
>however, in this case I think I'm justified with my code.  The current
>code is actually:
>
>        if ( lon != last_lon || lat != last_lat ) {
>

Ooops sorry about the code rearangment, I wrote the email from
memory and should have used cut and paste :-)

Anyway if ther is no change the direction part of the
calc_course_dist() is undefined.

Think about it
if I do not move,   what direction did I move in ?    :-)))

Better yet enable FPE exception reporting

// I think this is correct for Linux

======== cut ========

// Add the following code to main.cxx
// and set it up as
// SetSignals(CATCH_SIGFPE_FLAG)

#define CATCH_SIGINT_FLAG  1
#define CATCH_SIGFPE_FLAG  2
#define CATCH_SIGSEGV_FLAG 4
#define CATCH_SIGILL_FLAG  8
#define CATCH_SIGBUS_FLAG  16
#define CATCH_ALL_SIGNAL_FLAGS  31

#ifdef linux
#define SAY_IT_AGAIN
/* use sysv_signal in libc6 -- signal broken for SIGINT */
#define _XOPEN_SOURCE 1
#endif

#ifdef WIN32
 #ifndef __CYGWIN__
  #include <io.h>
 #endif
#define NO_GETPWNAM
#define NO_SOFT_LINKS
#define SAY_IT_AGAIN
#include <float.h>
#endif

#include <signal.h>

extern void SetSignals(int flags);
extern int matherr(int *);

static void HandleSignals(int sig);
static void InitializeSignals(void);

static int sg_catch_category;

static int setSignalsCalled= 0;

InitializeSignals()
{
#ifdef linux
 __setfpucw(0x1372);
#endif

#if defined(WIN32)
#if !defined(__CYGWIN__)
  /* Need to unmask exceptions after every interrupt under Windows  */
  /* Initialize floating-point package. */
        _fpreset();
  /* first argument specifies the exceptions that should remain masked */
  /* WARNING!!!! With Visual C++ 4.2 and Windows NT 4.0, the overflow
interrupt
     is not reported immediately - it shows up on the NEXT floating point
operation! */
        _controlfp( _EM_DENORMAL | _EM_INEXACT | _EM_UNDERFLOW | _EM_OVERFLOW,
_MCW_EM );
#else
        // !!!! NO CYGWIN SUPPORT YET
#endif
#endif
}

void SetSignals(int flags)
{
        if (!setSignalsCalled) InitializeSignals();
        signal(SIGINT, flags&1? &HandleSignals : SIG_DFL);
        signal(SIGFPE, flags&2? &HandleSignals : SIG_DFL);
        signal(SIGSEGV, flags&4? &HandleSignals : SIG_DFL);
        signal(SIGILL, flags&8? &HandleSignals : SIG_DFL);
#ifdef SIGBUS
        signal(SIGBUS, flags&16? &HandleSignals : SIG_DFL);
#endif
}


then
static void HandleSignals(int sig)
{
        signal(sig, &HandleSignals);
#ifdef SAY_IT_AGAIN
        InitializeSignals();
#endif
        if (sig==SIGINT)
        {
                sg_catch_category= 0x04;
                SG_LOG(SG_GENERAL, SG_ALERT,"Keyboard interrupt received (SIGINT)");
        }
        else if (sig==SIGFPE)
        {
                sg_catch_category= 0x01;
                SG_LOG(SG_GENERAL, SG_ALERT,"Floating point interrupt (SIGFPE)");
#define NASTY
#ifdef NASTY
                        SetSignals( 0 );
                        exit( 0 );
#endif
        }
        else if (sig==SIGSEGV)
                SG_LOG(SG_GENERAL, SG_ALERT,"Segmentation violation interrupt 
(SIGSEGV)");
        else if (sig==SIGILL)
                SG_LOG(SG_GENERAL, SG_ALERT,"Illegal instruction interrupt (SIGILL)");
#ifdef SIGBUS
        else if (sig==SIGBUS)
                SG_LOG(SG_GENERAL, SG_ALERT,"Misaligned address interrupt (SIGBUS)");
#endif
        SG_LOG(SG_GENERAL, SG_ALERT,"Unrecognized signal delivered to
HandleSignals");
}

======= cut =======

Cheers

Norman


_______________________________________________
Flightgear-devel mailing list
[EMAIL PROTECTED]
http://mail.flightgear.org/mailman/listinfo/flightgear-devel

Reply via email to