Skip to content

Commit c42d2f5

Browse files
authored
Merge pull request #4362 from OpenShot/protect-bounding-box
Protect against invalid items passed into setBoundingBox
2 parents fc9af3b + 8180f8e commit c42d2f5

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

src/timeline/js/functions.js

+30-20
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,24 @@ var bounding_box = Object();
221221

222222
// Build bounding box (since multiple items can be selected)
223223
function setBoundingBox(scope, item, item_type="clip") {
224-
var scrolling_tracks = $("#scrolling_tracks");
225-
var vert_scroll_offset = scrolling_tracks.scrollTop();
226-
var horz_scroll_offset = scrolling_tracks.scrollLeft();
227-
228-
var item_bottom = item.position().top + item.height() + vert_scroll_offset;
229-
var item_top = item.position().top + vert_scroll_offset;
230-
var item_left = item.position().left + horz_scroll_offset;
231-
var item_right = item.position().left + horz_scroll_offset + item.width();
224+
let scrolling_tracks = $("#scrolling_tracks");
225+
let vert_scroll_offset = scrolling_tracks.scrollTop();
226+
let horz_scroll_offset = scrolling_tracks.scrollLeft();
227+
let item_bottom = 0;
228+
let item_top = 0;
229+
let item_left = 0;
230+
let item_right = 0;
231+
232+
if (item && item.position()) {
233+
item_bottom = item.position().top + item.height() + vert_scroll_offset;
234+
item_top = item.position().top + vert_scroll_offset;
235+
item_left = item.position().left + horz_scroll_offset;
236+
item_right = item.position().left + horz_scroll_offset + item.width();
237+
} else {
238+
// Protect against invalid item (sentry)
239+
// TODO: Determine what causes an invalid item to be passed into this function
240+
return;
241+
}
232242

233243
if (jQuery.isEmptyObject(bounding_box)) {
234244
bounding_box.left = item_left;
@@ -245,8 +255,8 @@ function setBoundingBox(scope, item, item_type="clip") {
245255
if (item_right > bounding_box.right) { bounding_box.right = item_right; }
246256

247257
// compare height and width of bounding box (take the largest number)
248-
var height = bounding_box.bottom - bounding_box.top;
249-
var width = bounding_box.right - bounding_box.left;
258+
let height = bounding_box.bottom - bounding_box.top;
259+
let width = bounding_box.right - bounding_box.left;
250260
if (height > bounding_box.height) { bounding_box.height = height; }
251261
if (width > bounding_box.width) { bounding_box.width = width; }
252262
}
@@ -268,12 +278,12 @@ function setBoundingBox(scope, item, item_type="clip") {
268278
// Unless playhead mode, where we don't want to ignore any selected clips
269279
bounding_box.selected_ids = {};
270280
if (item_type !== "playhead") {
271-
for (var clip_index = 0; clip_index < scope.project.clips.length; clip_index++) {
281+
for (let clip_index = 0; clip_index < scope.project.clips.length; clip_index++) {
272282
if (scope.project.clips[clip_index].selected) {
273283
bounding_box.selected_ids[scope.project.clips[clip_index].id] = true;
274284
}
275285
}
276-
for (var effect_index = 0; effect_index < scope.project.effects.length; effect_index++) {
286+
for (let effect_index = 0; effect_index < scope.project.effects.length; effect_index++) {
277287
if (scope.project.effects[effect_index].selected) {
278288
bounding_box.selected_ids[scope.project.effects[effect_index].id] = true;
279289
}
@@ -367,7 +377,7 @@ global_primes = new Set();
367377
* Stores primes in a set for better performance in the future.
368378
* If some primes have been found, start with that list,
369379
* and check the remaining numbers up to n.
370-
* @param {any number} n
380+
* @param {any number} n
371381
* @returns the list of all primes less than n
372382
*/
373383
function primesUpTo(n) {
@@ -394,7 +404,7 @@ function primesUpTo(n) {
394404
/**
395405
* Every integer is either prime,
396406
* is the product of some list of primes.
397-
* @param {integer to factor} n
407+
* @param {integer to factor} n
398408
* @returns the list of prime factors of n
399409
*/
400410
function primeFactorsOf(n) {
@@ -417,13 +427,13 @@ function primeFactorsOf(n) {
417427
* From the pixels per second of the project,
418428
* Find a number of frames between each ruler mark,
419429
* such that the tick marks remain at least 50px apart.
420-
*
430+
*
421431
* Increases the number of frames by factors of FPS.
422432
* This way each tick should land neatly on a second mark
423-
* @param {Pixels per second} pps
424-
* @param fps_num
425-
* @param fps_den
426-
* @returns
433+
* @param {Pixels per second} pps
434+
* @param fps_num
435+
* @param fps_den
436+
* @returns
427437
*/
428438
function framesPerTick(pps, fps_num, fps_den) {
429439
fps = fps_num / fps_den;
@@ -434,7 +444,7 @@ function framesPerTick(pps, fps_num, fps_den) {
434444
while (pixels() < 40) {
435445
frames *= factors.shift() || 2;
436446
}
437-
447+
438448
return frames;
439449
}
440450

0 commit comments

Comments
 (0)