prevent crashes on bad data

This commit is contained in:
David Rose 2005-09-22 18:57:55 +00:00
parent 942f595c7f
commit b5d0ee8a7a
3 changed files with 17 additions and 3 deletions

View File

@ -98,9 +98,6 @@ from_camera(int camera_index, int z) {
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)) {
page._color.clear();
return false;
@ -269,6 +266,11 @@ reconsider_video_properties(const OpenCVTexture::VideoStream &stream,
if (stream.is_from_file()) {
frame_rate = cvGetCaptureProperty(stream._capture, CV_CAP_PROP_FPS);
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 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);
}
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,
T_unsigned_byte, z)) {
return false;

View File

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

View File

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