Skip to content

Commit

Permalink
Fix race condition causing clip to clip parents not to work. Adding a…
Browse files Browse the repository at this point in the history
… late-bound check, to ensure we have attached the clip on first call.
  • Loading branch information
jonoomph committed Mar 2, 2024
1 parent 620e894 commit 8b47373
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/Clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,24 @@ openshot::EffectBase* Clip::GetEffect(const std::string& id)
return nullptr;
}

// Return the associated ParentClip (if any)
openshot::Clip* Clip::GetParentClip() {
if (!parentObjectId.empty() && (!parentClipObject && !parentTrackedObject)) {
// Attach parent clip OR object to this clip
AttachToObject(parentObjectId);

Check warning on line 486 in src/Clip.cpp

View check run for this annotation

Codecov / codecov/patch

src/Clip.cpp#L486

Added line #L486 was not covered by tests
}
return parentClipObject;
}

// Return the associated Parent Tracked Object (if any)
std::shared_ptr<openshot::TrackedObjectBase> Clip::GetParentTrackedObject() {
if (!parentObjectId.empty() && (!parentClipObject && !parentTrackedObject)) {
// Attach parent clip OR object to this clip
AttachToObject(parentObjectId);

Check warning on line 495 in src/Clip.cpp

View check run for this annotation

Codecov / codecov/patch

src/Clip.cpp#L495

Added line #L495 was not covered by tests
}
return parentTrackedObject;
}

// Get file extension
std::string Clip::get_file_extension(std::string path)
{
Expand Down Expand Up @@ -1409,7 +1427,7 @@ QTransform Clip::get_transform(std::shared_ptr<Frame> frame, int width, int heig
float parentObject_rotation = 0.0;

// Get the parentClipObject properties
if (parentClipObject){
if (GetParentClip()){
// Get the start trim position of the parent clip
long parent_start_offset = parentClipObject->Start() * info.fps.ToDouble();
long parent_frame_number = frame->number + parent_start_offset;

Check warning on line 1433 in src/Clip.cpp

View check run for this annotation

Codecov / codecov/patch

src/Clip.cpp#L1432-L1433

Added lines #L1432 - L1433 were not covered by tests
Expand All @@ -1425,7 +1443,7 @@ QTransform Clip::get_transform(std::shared_ptr<Frame> frame, int width, int heig
}

// Get the parentTrackedObject properties
if (parentTrackedObject){
if (GetParentTrackedObject()){
// Get the attached object's parent clip's properties
Clip* parentClip = (Clip*) parentTrackedObject->ParentClip();
if (parentClip)
Expand Down
6 changes: 6 additions & 0 deletions src/Clip.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ namespace openshot {
/// Close the internal reader
void Close() override;

/// Return the associated ParentClip (if any)
openshot::Clip* GetParentClip();

/// Return the associated Parent Tracked Object (if any)
std::shared_ptr<openshot::TrackedObjectBase> GetParentTrackedObject();

/// Return the list of effects on the timeline
std::list<openshot::EffectBase*> Effects() { return effects; };

Expand Down

0 comments on commit 8b47373

Please sign in to comment.