Skip to content

Commit

Permalink
Scripting: Fixed crash after using tiled.project
Browse files Browse the repository at this point in the history
Crash caused by a double-deletion of the EditableProject, since both
the Project as well as the ProjectDocument classes were deleting it
from their destructors (in the Object and Document superclasses,
respectively).

This issue was introduced in 4244060.
  • Loading branch information
bjorn committed Apr 26, 2024
1 parent a376878 commit 70c0f63
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/tiled/projectdocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ ProjectDocument::ProjectDocument(std::unique_ptr<Project> project, QObject *pare
this, [this] { mProject->save(); });
}

ProjectDocument::~ProjectDocument()
{
// The Editable needs to be deleted before the Project, otherwise ~Object()
// will delete it, whereas the editable is actually owned by the Document.
mEditable.reset();
}

QString ProjectDocument::displayName() const
{
return mProject->fileName();
Expand Down
1 change: 1 addition & 0 deletions src/tiled/projectdocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class ProjectDocument : public Document

public:
ProjectDocument(std::unique_ptr<Project> project, QObject *parent = nullptr);
~ProjectDocument() override;

QString displayName() const override;
FileFormat *writerFormat() const override;
Expand Down

0 comments on commit 70c0f63

Please sign in to comment.