fixed nan propogation error
authorhgn <hgodden00@gmail.com>
Tue, 6 Jun 2023 03:42:21 +0000 (04:42 +0100)
committerhgn <hgodden00@gmail.com>
Tue, 6 Jun 2023 03:42:21 +0000 (04:42 +0100)
vg_async.h
vg_audio.h
vg_build.h
vg_m.h

index fd65c0db77ba3484882aa066866d01e21b8c14fe..c142ad81e247967c33e853921f678b2d8e1be2ea 100644 (file)
@@ -40,7 +40,6 @@ VG_STATIC enum engine_status _vg_engine_status(void);
 VG_STATIC vg_async_item *vg_async_alloc( u32 size )
 {
    /* ditch out here if engine crashed. this serves as the 'quit checking' */
-
    if( _vg_engine_status() == k_engine_status_crashed ){
       assert( vg_thread_purpose() == k_thread_purpose_loader );
       longjmp( vg.env_loader_exit, 1 );
index 4d203bf9c1aafae550af5dc158bac615b108ba7c..09998718a11ada12f06aeb68f40d5dd126d02573 100644 (file)
@@ -94,7 +94,7 @@ struct audio_clip{
    };
 };
 
-static struct vg_audio_system{
+struct vg_audio_system{
    SDL_AudioDeviceID sdl_output_device;
 
    void             *audio_pool, 
@@ -205,7 +205,7 @@ static struct vg_audio_system{
    float             internal_global_volume,
                      external_global_volume;
 }
-vg_audio = { .external_global_volume = 1.0f };
+static vg_audio = { .external_global_volume = 1.0f };
 
 #include "vg/vg_audio_dsp.h"
 
@@ -850,10 +850,25 @@ static void audio_channel_mix( audio_channel *ch, float *buffer )
          }
       }
 
-      if( !vg_validf( framevol_l ) ) vg_fatal_error( "NaN left channel" );
-      if( !vg_validf( framevol_r ) ) vg_fatal_error( "NaN right channel" );
-      if( !vg_validf( frame_samplerate ) ) 
-         vg_fatal_error( "NaN sample rate" );
+      if( !vg_validf( framevol_l ) || 
+          !vg_validf( framevol_r ) ||
+          !vg_validf( frame_samplerate ) ){
+         vg_fatal_error( "Invalid sampling conditions.\n"
+                         "This crash is to protect your ears.\n"
+                         "  channel: %p (%s)\n"
+                         "  sample_rate: %f\n"
+                         "  volume: L%f R%f\n"
+                         "  listener: %.2f %.2f %.2f [%.2f %.2f %.2f]\n",
+                         ch, ch->name, frame_samplerate, 
+                         framevol_l, framevol_r,
+                         vg_audio.internal_listener_pos[0],
+                         vg_audio.internal_listener_pos[1],
+                         vg_audio.internal_listener_pos[2],
+                         vg_audio.internal_listener_ears[0],
+                         vg_audio.internal_listener_ears[1],
+                         vg_audio.internal_listener_ears[2]
+                         );
+      }
    }
 
    u32 buffer_length = AUDIO_MIX_FRAME_SIZE;
index 54c74e2ec8c50c5eaa0d2ca28e8aa5f69bdbf1fa..873eb3981e41464b486026581762dad063e2c286 100644 (file)
@@ -217,7 +217,8 @@ void vg_build(void)
       if( (vg_compiler.compiler == k_compiler_gcc) ||
           (vg_compiler.compiler == k_compiler_clang ) )
       {
-         strcat( cmd, "-rdynamic -fsanitize=address " );
+         strcat( cmd, "-rdynamic -fsanitize=address "
+                      "-fPIE -fstack-protector-strong " );
       }
 
       strcat( cmd, "\\\n" );
diff --git a/vg_m.h b/vg_m.h
index c07f38984e07ada336ffe5c8328fef6649a3243a..833f1f01598a628a4c09df3c873c1a7cef7a3644 100644 (file)
--- a/vg_m.h
+++ b/vg_m.h
@@ -573,11 +573,15 @@ static inline void q_mul( v4f q, v4f q1, v4f d )
 
 static inline void q_normalize( v4f q )
 {
-   f32 s = 1.0f/ sqrtf(v4_dot(q,q));
-   q[0] *= s;
-   q[1] *= s;
-   q[2] *= s;
-   q[3] *= s;
+   f32 l2 = v4_dot(q,q);
+   if( l2 < 0.00001f ) q_identity( q );
+   else {
+      f32 s = 1.0f/sqrtf(l2);
+      q[0] *= s;
+      q[1] *= s;
+      q[2] *= s;
+      q[3] *= s;
+   }
 }
 
 static inline void q_inv( v4f q, v4f d )
@@ -2160,7 +2164,7 @@ static void vg_rand_seed( unsigned long seed )
     * Programming," Vol. 2 (2nd Ed.) pp.102.
     */
    vg_rand.mt[0] = seed & 0xffffffff;
-   for( vg_rand.index=1; vg_rand.index<MT_STATE_VECTOR_LENGTH; vg_rand.index++ ){
+   for( vg_rand.index=1; vg_rand.index<MT_STATE_VECTOR_LENGTH; vg_rand.index++){
       vg_rand.mt[vg_rand.index] = 
          (6069 * vg_rand.mt[vg_rand.index-1]) & 0xffffffff;
    }