فهرست منبع

prevent crashes on bad data

David Rose 20 سال پیش
والد
کامیت
b5d0ee8a7a
3فایلهای تغییر یافته به همراه17 افزوده شده و 3 حذف شده
  1. 12 3
      panda/src/grutil/openCVTexture.cxx
  2. 3 0
      panda/src/putil/animInterface.I
  3. 2 0
      panda/src/putil/animInterface.cxx

+ 12 - 3
panda/src/grutil/openCVTexture.cxx

@@ -98,9 +98,6 @@ from_camera(int camera_index, int z) {
     return false;
     return false;
   }
   }
 
 
-  int width = cvGetCaptureProperty(page._color._capture, CV_CAP_PROP_FRAME_WIDTH);
-  int height = cvGetCaptureProperty(page._color._capture, CV_CAP_PROP_FRAME_HEIGHT);
-
   if (!reconsider_video_properties(page._color, 3, z)) {
   if (!reconsider_video_properties(page._color, 3, z)) {
     page._color.clear();
     page._color.clear();
     return false;
     return false;
@@ -269,6 +266,11 @@ reconsider_video_properties(const OpenCVTexture::VideoStream &stream,
   if (stream.is_from_file()) {
   if (stream.is_from_file()) {
     frame_rate = cvGetCaptureProperty(stream._capture, CV_CAP_PROP_FPS);
     frame_rate = cvGetCaptureProperty(stream._capture, CV_CAP_PROP_FPS);
     num_frames = (int)cvGetCaptureProperty(stream._capture, CV_CAP_PROP_FRAME_COUNT);
     num_frames = (int)cvGetCaptureProperty(stream._capture, CV_CAP_PROP_FRAME_COUNT);
+    if (grutil_cat.is_debug()) {
+      grutil_cat.debug()
+        << "Loaded " << stream._filename << ", " << num_frames << " frames at "
+        << frame_rate << " fps\n";
+    }
   }
   }
   int width = (int)cvGetCaptureProperty(stream._capture, CV_CAP_PROP_FRAME_WIDTH);
   int width = (int)cvGetCaptureProperty(stream._capture, CV_CAP_PROP_FRAME_WIDTH);
   int height = (int)cvGetCaptureProperty(stream._capture, CV_CAP_PROP_FRAME_HEIGHT);
   int height = (int)cvGetCaptureProperty(stream._capture, CV_CAP_PROP_FRAME_HEIGHT);
@@ -281,6 +283,13 @@ reconsider_video_properties(const OpenCVTexture::VideoStream &stream,
     y_size = up_to_power_2(height);
     y_size = up_to_power_2(height);
   }
   }
 
 
+  if (grutil_cat.is_debug()) {
+    grutil_cat.debug()
+      << "Video stream is " << width << " by " << height 
+      << " pixels; fitting in texture " << x_size << " by "
+      << y_size << " texels.\n";
+  }
+
   if (!reconsider_image_properties(x_size, y_size, num_components,
   if (!reconsider_image_properties(x_size, y_size, num_components,
 				   T_unsigned_byte, z)) {
 				   T_unsigned_byte, z)) {
     return false;
     return false;

+ 3 - 0
panda/src/putil/animInterface.I

@@ -126,6 +126,9 @@ get_num_frames() const {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE int AnimInterface::
 INLINE int AnimInterface::
 get_frame() const {
 get_frame() const {
+  if (get_num_frames() <= 0) {
+    return 0;
+  }
   return cmod(get_full_frame(), get_num_frames());
   return cmod(get_full_frame(), get_num_frames());
 }
 }
 
 

+ 2 - 0
panda/src/putil/animInterface.cxx

@@ -252,10 +252,12 @@ get_full_fframe() const {
     return min(max(get_f(), 0.0), _play_frames) + _start_frame;
     return min(max(get_f(), 0.0), _play_frames) + _start_frame;
 
 
   case PM_loop:
   case PM_loop:
+    nassertr(_play_frames >= 0.0, 0.0);
     return cmod(get_f(), _play_frames) + _start_frame;
     return cmod(get_f(), _play_frames) + _start_frame;
 
 
   case PM_pingpong:
   case PM_pingpong:
     {
     {
+      nassertr(_play_frames >= 0.0, 0.0);
       double f = cmod(get_f(), _play_frames * 2.0);
       double f = cmod(get_f(), _play_frames * 2.0);
       if (f > _play_frames) {
       if (f > _play_frames) {
 	return (_play_frames * 2.0 - f) + _start_frame;
 	return (_play_frames * 2.0 - f) + _start_frame;