Skip to content

Commit bacf095

Browse files
authored
fixed image bounds error status null bug + test case (#1896)
* fixed image bounds error status null bug + test case Signed-off-by: Yingjie Wang <[email protected]>
1 parent 8405a57 commit bacf095

File tree

4 files changed

+74
-10
lines changed

4 files changed

+74
-10
lines changed

src/opentimelineio/clip.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,21 +190,32 @@ std::optional<IMATH_NAMESPACE::Box2d>
190190
Clip::available_image_bounds(ErrorStatus* error_status) const
191191
{
192192
auto active_media = media_reference();
193+
194+
//this code path most likely never runs since a null or empty media_reference gets
195+
//replaced with a placeholder value when instantiated
193196
if (!active_media)
194197
{
195-
*error_status = ErrorStatus(
196-
ErrorStatus::CANNOT_COMPUTE_BOUNDS,
197-
"No image bounds set on clip",
198-
this);
198+
if(error_status)
199+
{
200+
*error_status = ErrorStatus(
201+
ErrorStatus::CANNOT_COMPUTE_BOUNDS,
202+
"No image bounds set on clip",
203+
this);
204+
}
205+
199206
return std::optional<IMATH_NAMESPACE::Box2d>();
200207
}
201208

202209
if (!active_media->available_image_bounds())
203210
{
204-
*error_status = ErrorStatus(
205-
ErrorStatus::CANNOT_COMPUTE_BOUNDS,
206-
"No image bounds set on media reference on clip",
207-
this);
211+
if(error_status)
212+
{
213+
*error_status = ErrorStatus(
214+
ErrorStatus::CANNOT_COMPUTE_BOUNDS,
215+
"No image bounds set on media reference on clip",
216+
this);
217+
}
218+
208219
return std::optional<IMATH_NAMESPACE::Box2d>();
209220
}
210221

src/opentimelineio/clip.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class Clip : public Item
8484
available_range(ErrorStatus* error_status = nullptr) const override;
8585

8686
std::optional<IMATH_NAMESPACE::Box2d>
87-
available_image_bounds(ErrorStatus* error_status) const override;
87+
available_image_bounds(ErrorStatus* error_status = nullptr) const override;
8888

8989
protected:
9090
virtual ~Clip();

src/opentimelineio/composable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Composable : public SerializableObjectWithMetadata
4747

4848
/// @brief Return the available image bounds.
4949
virtual std::optional<IMATH_NAMESPACE::Box2d>
50-
available_image_bounds(ErrorStatus* error_status) const;
50+
available_image_bounds(ErrorStatus* error_status = nullptr) const;
5151

5252
protected:
5353
bool _set_parent(Composition*) noexcept;

tests/test_clip.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,59 @@ main(int argc, char** argv)
260260
assertEqual(marker->color().c_str(), red);
261261
});
262262

263+
// test to ensure null error_status pointers are correctly handled
264+
tests.add_test("test_error_ptr_null", [] {
265+
266+
using namespace otio;
267+
268+
// tests for no image bounds on media reference on clip
269+
SerializableObject::Retainer<Clip> clip(new Clip);
270+
271+
// check that there is an error, and that it's the correct error
272+
otio::ErrorStatus mr_bounds_error;
273+
clip->available_image_bounds(&mr_bounds_error);
274+
assertTrue(otio::is_error(mr_bounds_error));
275+
assertEqual(
276+
mr_bounds_error.outcome,
277+
otio::ErrorStatus::CANNOT_COMPUTE_BOUNDS);
278+
279+
// check that if null ptr, nothing happens
280+
otio::ErrorStatus* null_test = nullptr;
281+
282+
assertEqual(
283+
clip->available_image_bounds(null_test), std::optional<IMATH_NAMESPACE::Box2d>()
284+
);
285+
});
286+
287+
// test to ensure null error_status pointers are correctly handled
288+
// when there's no media reference
289+
tests.add_test("test_error_ptr_null_no_media", [] {
290+
using namespace otio;
291+
292+
SerializableObject::Retainer<Clip> clip(new Clip);
293+
294+
// set media reference to empty
295+
Clip::MediaReferences empty_mrs;
296+
empty_mrs["empty"] = nullptr;
297+
clip->set_media_references(empty_mrs, "empty");
298+
299+
otio::ErrorStatus bounds_error_no_mr;
300+
clip->available_image_bounds(&bounds_error_no_mr);
301+
assertTrue(otio::is_error(bounds_error_no_mr));
302+
303+
assertEqual(
304+
bounds_error_no_mr.outcome,
305+
otio::ErrorStatus::CANNOT_COMPUTE_BOUNDS);
306+
307+
// std::cout<< "bounds error details: " << bounds_error_no_mr.details << std::endl;
308+
309+
otio::ErrorStatus* null_test_no_mr = nullptr;
310+
311+
assertEqual(
312+
clip->available_image_bounds(null_test_no_mr), std::optional<IMATH_NAMESPACE::Box2d>()
313+
);
314+
});
315+
263316
tests.run(argc, argv);
264317
return 0;
265318
}

0 commit comments

Comments
 (0)