Browse Source

general: fix various unprotected debug() outputs

These should be protected by an is_debug() check so that they can be optimized out properly in a release build.  Setting check-debug-notify-protect in Config.prc can be used to track down cases of missed checks.
rdb 6 years ago
parent
commit
42dff65e4d

+ 6 - 2
panda/src/audiotraits/openalAudioManager.cxx

@@ -252,7 +252,9 @@ select_audio_device() {
     devices = (const char *)alcGetString(nullptr, ALC_ALL_DEVICES_SPECIFIER);
 
     if (devices) {
-      audio_cat.debug() << "All OpenAL devices:\n";
+      if (audio_cat.is_debug()) {
+        audio_cat.debug() << "All OpenAL devices:\n";
+      }
 
       while (*devices) {
         string device(devices);
@@ -280,7 +282,9 @@ select_audio_device() {
     devices = (const char *)alcGetString(nullptr, ALC_DEVICE_SPECIFIER);
 
     if (devices) {
-      audio_cat.debug() << "OpenAL drivers:\n";
+      if (audio_cat.is_debug()) {
+        audio_cat.debug() << "OpenAL drivers:\n";
+      }
 
       while (*devices) {
         string device(devices);

+ 18 - 6
panda/src/glstuff/glGraphicsBuffer_src.cxx

@@ -778,7 +778,9 @@ bind_slot(int layer, bool rb_resize, Texture **attach, RenderTexturePlane slot,
     }
 
     if (attachpoint == GL_DEPTH_ATTACHMENT_EXT) {
-      GLCAT.debug() << "Binding texture " << *tex << " to depth attachment.\n";
+      if (GLCAT.is_debug()) {
+        GLCAT.debug() << "Binding texture " << *tex << " to depth attachment.\n";
+      }
 
       attach_tex(layer, 0, tex, GL_DEPTH_ATTACHMENT_EXT);
 
@@ -789,7 +791,9 @@ bind_slot(int layer, bool rb_resize, Texture **attach, RenderTexturePlane slot,
 #endif
 
       if (slot == RTP_depth_stencil) {
-        GLCAT.debug() << "Binding texture " << *tex << " to stencil attachment.\n";
+        if (GLCAT.is_debug()) {
+          GLCAT.debug() << "Binding texture " << *tex << " to stencil attachment.\n";
+        }
 
         attach_tex(layer, 0, tex, GL_STENCIL_ATTACHMENT_EXT);
 
@@ -801,7 +805,9 @@ bind_slot(int layer, bool rb_resize, Texture **attach, RenderTexturePlane slot,
       }
 
     } else {
-      GLCAT.debug() << "Binding texture " << *tex << " to color attachment.\n";
+      if (GLCAT.is_debug()) {
+        GLCAT.debug() << "Binding texture " << *tex << " to color attachment.\n";
+      }
 
       attach_tex(layer, 0, tex, attachpoint);
 
@@ -988,7 +994,9 @@ bind_slot(int layer, bool rb_resize, Texture **attach, RenderTexturePlane slot,
     glgsg->_glBindRenderbuffer(GL_RENDERBUFFER_EXT, _rb[slot]);
 
     if (slot == RTP_depth_stencil) {
-      GLCAT.debug() << "Creating depth stencil renderbuffer.\n";
+      if (GLCAT.is_debug()) {
+        GLCAT.debug() << "Creating depth stencil renderbuffer.\n";
+      }
       // Allocate renderbuffer storage for depth stencil.
       GLint depth_size = 0, stencil_size = 0;
       glgsg->_glRenderbufferStorage(GL_RENDERBUFFER_EXT, gl_format, _rb_size_x, _rb_size_y);
@@ -1014,7 +1022,9 @@ bind_slot(int layer, bool rb_resize, Texture **attach, RenderTexturePlane slot,
       report_my_gl_errors();
 
     } else if (slot == RTP_depth) {
-      GLCAT.debug() << "Creating depth renderbuffer.\n";
+      if (GLCAT.is_debug()) {
+        GLCAT.debug() << "Creating depth renderbuffer.\n";
+      }
       // Allocate renderbuffer storage for regular depth.
       GLint depth_size = 0;
       glgsg->_glRenderbufferStorage(GL_RENDERBUFFER_EXT, gl_format, _rb_size_x, _rb_size_y);
@@ -1052,7 +1062,9 @@ bind_slot(int layer, bool rb_resize, Texture **attach, RenderTexturePlane slot,
       report_my_gl_errors();
 
     } else {
-      GLCAT.debug() << "Creating color renderbuffer.\n";
+      if (GLCAT.is_debug()) {
+        GLCAT.debug() << "Creating color renderbuffer.\n";
+      }
       glgsg->_glRenderbufferStorage(GL_RENDERBUFFER_EXT, gl_format, _rb_size_x, _rb_size_y);
 
       GLint red_size = 0, green_size = 0, blue_size = 0, alpha_size = 0;

+ 6 - 4
panda/src/glstuff/glGraphicsStateGuardian_src.cxx

@@ -722,10 +722,12 @@ reset() {
                    || has_extension("GL_KHR_debug")
                    || has_extension("GL_ARB_debug_output");
 
-    if (_supports_debug) {
-      GLCAT.debug() << "gl-debug supported, but NOT enabled.\n";
-    } else {
-      GLCAT.debug() << "gl-debug disabled and unsupported.\n";
+    if (GLCAT.is_debug()) {
+      if (_supports_debug) {
+        GLCAT.debug() << "gl-debug supported, but NOT enabled.\n";
+      } else {
+        GLCAT.debug() << "gl-debug disabled and unsupported.\n";
+      }
     }
   }
 

+ 12 - 6
panda/src/gobj/shader.cxx

@@ -3274,8 +3274,10 @@ load(const Filename &file, ShaderLanguage lang) {
       shader_cat.info()
         << "Shader " << file << " was modified on disk, reloading.\n";
     } else {
-      shader_cat.debug()
-        << "Shader " << file << " was found in shader cache.\n";
+      if (shader_cat.is_debug()) {
+        shader_cat.debug()
+          << "Shader " << file << " was found in shader cache.\n";
+      }
       return i->second;
     }
   }
@@ -3312,8 +3314,10 @@ load(ShaderLanguage lang, const Filename &vertex,
       shader_cat.info()
         << "Shader was modified on disk, reloading.\n";
     } else {
-      shader_cat.debug()
-        << "Shader was found in shader cache.\n";
+      if (shader_cat.is_debug()) {
+        shader_cat.debug()
+          << "Shader was found in shader cache.\n";
+      }
       return i->second;
     }
   }
@@ -3365,8 +3369,10 @@ load_compute(ShaderLanguage lang, const Filename &fn) {
       shader_cat.info()
         << "Compute shader " << fn << " was modified on disk, reloading.\n";
     } else {
-      shader_cat.debug()
-        << "Compute shader " << fn << " was found in shader cache.\n";
+      if (shader_cat.is_debug()) {
+        shader_cat.debug()
+          << "Compute shader " << fn << " was found in shader cache.\n";
+      }
       return i->second;
     }
   }

+ 2 - 2
panda/src/movies/movieTypeRegistry.cxx

@@ -90,7 +90,7 @@ register_audio_type(MakeAudioFunc func, const string &extensions) {
     if (_audio_type_registry.count(*wi)) {
       movies_cat->warning()
         << "Attempt to register multiple audio types with extension " << (*wi) << "\n";
-    } else {
+    } else if (movies_cat->is_debug()) {
       movies_cat->debug()
         << "Registered audio type with extension " << (*wi) << "\n";
     }
@@ -219,7 +219,7 @@ register_video_type(MakeVideoFunc func, const string &extensions) {
     if (_video_type_registry.count(*wi)) {
       movies_cat->warning()
         << "Attempt to register multiple video types with extension " << (*wi) << "\n";
-    } else {
+    } else if (movies_cat->is_debug()) {
       movies_cat->debug()
         << "Registered video type with extension " << (*wi) << "\n";
     }

+ 51 - 31
panda/src/pnmimagetypes/pnmFileTypePNG.cxx

@@ -227,10 +227,12 @@ Reader(PNMFileType *type, istream *file, bool owns_file, string magic_number) :
     }
   }
 
-  pnmimage_png_cat.debug()
-    << "width = " << width << " height = " << height << " bit_depth = "
-    << bit_depth << " color_type = " << color_type
-    << " color_space = " << _color_space << "\n";
+  if (pnmimage_png_cat.is_debug()) {
+    pnmimage_png_cat.debug()
+      << "width = " << width << " height = " << height << " bit_depth = "
+      << bit_depth << " color_type = " << color_type
+      << " color_space = " << _color_space << "\n";
+  }
 
   _x_size = width;
   _y_size = height;
@@ -242,32 +244,42 @@ Reader(PNMFileType *type, istream *file, bool owns_file, string magic_number) :
 
   switch (color_type) {
   case PNG_COLOR_TYPE_GRAY:
-    pnmimage_png_cat.debug()
-      << "PNG_COLOR_TYPE_GRAY\n";
+    if (pnmimage_png_cat.is_debug()) {
+      pnmimage_png_cat.debug()
+        << "PNG_COLOR_TYPE_GRAY\n";
+    }
     _num_channels = 1;
     break;
 
   case PNG_COLOR_TYPE_GRAY_ALPHA:
-    pnmimage_png_cat.debug()
-      << "PNG_COLOR_TYPE_GRAY_ALPHA\n";
+    if (pnmimage_png_cat.is_debug()) {
+      pnmimage_png_cat.debug()
+        << "PNG_COLOR_TYPE_GRAY_ALPHA\n";
+    }
     _num_channels = 2;
     break;
 
   case PNG_COLOR_TYPE_RGB:
-    pnmimage_png_cat.debug()
-      << "PNG_COLOR_TYPE_RGB\n";
+    if (pnmimage_png_cat.is_debug()) {
+      pnmimage_png_cat.debug()
+        << "PNG_COLOR_TYPE_RGB\n";
+    }
     _num_channels = 3;
     break;
 
   case PNG_COLOR_TYPE_RGB_ALPHA:
-    pnmimage_png_cat.debug()
-      << "PNG_COLOR_TYPE_RGB_ALPHA\n";
+    if (pnmimage_png_cat.is_debug()) {
+      pnmimage_png_cat.debug()
+        << "PNG_COLOR_TYPE_RGB_ALPHA\n";
+    }
     _num_channels = 4;
     break;
 
   case PNG_COLOR_TYPE_PALETTE:
-    pnmimage_png_cat.debug()
-      << "PNG_COLOR_TYPE_PALETTE\n";
+    if (pnmimage_png_cat.is_debug()) {
+      pnmimage_png_cat.debug()
+        << "PNG_COLOR_TYPE_PALETTE\n";
+    }
     png_set_palette_to_rgb(_png);
     _maxval = 255;
     _num_channels = 3;
@@ -566,8 +578,10 @@ write_data(xel *array, xelval *alpha_data) {
   if (png_palette) {
     if (png_bit_depth <= 8) {
       if (compute_palette(palette, array, alpha_data, png_max_palette)) {
-        pnmimage_png_cat.debug()
-          << palette.size() << " colors found.\n";
+        if (pnmimage_png_cat.is_debug()) {
+          pnmimage_png_cat.debug()
+            << palette.size() << " colors found.\n";
+        }
 
         int palette_bit_depth = make_png_bit_depth(pm_maxvaltobits(palette.size() - 1));
 
@@ -581,10 +595,12 @@ write_data(xel *array, xelval *alpha_data) {
 
         if (palette_bit_depth < total_bits ||
             _maxval != (1 << true_bit_depth) - 1) {
-          pnmimage_png_cat.debug()
-            << "palette bit depth of " << palette_bit_depth
-            << " improves on bit depth of " << total_bits
-            << "; making a palette image.\n";
+          if (pnmimage_png_cat.is_debug()) {
+            pnmimage_png_cat.debug()
+              << "palette bit depth of " << palette_bit_depth
+              << " improves on bit depth of " << total_bits
+              << "; making a palette image.\n";
+          }
 
           color_type = PNG_COLOR_TYPE_PALETTE;
 
@@ -611,36 +627,40 @@ write_data(xel *array, xelval *alpha_data) {
 
           png_set_PLTE(_png, _info, png_palette_table, palette.size());
           if (has_alpha()) {
-            pnmimage_png_cat.debug()
-              << "palette contains " << num_alpha << " transparent entries.\n";
+            if (pnmimage_png_cat.is_debug()) {
+              pnmimage_png_cat.debug()
+                << "palette contains " << num_alpha << " transparent entries.\n";
+            }
             png_set_tRNS(_png, _info, png_trans, num_alpha, nullptr);
           }
-        } else {
+        } else if (pnmimage_png_cat.is_debug()) {
           pnmimage_png_cat.debug()
             << "palette bit depth of " << palette_bit_depth
             << " does not improve on bit depth of " << total_bits
             << "; not making a palette image.\n";
         }
 
-      } else {
+      } else if (pnmimage_png_cat.is_debug()) {
         pnmimage_png_cat.debug()
           << "more than " << png_max_palette
           << " colors found; not making a palette image.\n";
       }
-    } else {
+    } else if (pnmimage_png_cat.is_debug()) {
       pnmimage_png_cat.debug()
         << "maxval exceeds 255; not making a palette image.\n";
     }
-  } else {
+  } else if (pnmimage_png_cat.is_debug()) {
     pnmimage_png_cat.debug()
       << "palette images are not enabled.\n";
   }
 
-  pnmimage_png_cat.debug()
-    << "width = " << _x_size << " height = " << _y_size
-    << " maxval = " << _maxval << " bit_depth = "
-    << png_bit_depth << " color_type = " << color_type
-    << " color_space = " << _color_space << "\n";
+  if (pnmimage_png_cat.is_debug()) {
+    pnmimage_png_cat.debug()
+      << "width = " << _x_size << " height = " << _y_size
+      << " maxval = " << _maxval << " bit_depth = "
+      << png_bit_depth << " color_type = " << color_type
+      << " color_space = " << _color_space << "\n";
+  }
 
   png_set_IHDR(_png, _info, _x_size, _y_size, png_bit_depth,
                color_type, PNG_INTERLACE_NONE,