Skip to content

Commit

Permalink
Fix crash: possible property race (#617)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kicer86 committed Mar 4, 2024
1 parent 79582f9 commit b43b8e1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/core/function_wrappers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ void invokeMethod(Obj* object, const F& method, Args&&... args) requires std::is
}


// like invokeMethod but postponed
template<typename Obj, typename F, typename... Args>
void invokeMethodLater(Obj* object, const F& method, Args&&... args) requires std::is_base_of<QObject, Obj>::value
{
QMetaObject::invokeMethod(object, [object, method, ...args = std::forward<Args>(args)]() mutable
{
(object->*method)(std::forward<Args>(args)...);
}, Qt::QueuedConnection);
}


// Works as extended invokeMethod but waits for results
template<typename T, typename ObjT, typename F, typename... Args>
requires std::is_base_of_v<QObject, ObjT>
Expand Down
6 changes: 6 additions & 0 deletions src/gui/desktop/quick_items/media_view_ctrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ MediaViewCtrl::Mode MediaViewCtrl::mode() const

void MediaViewCtrl::setPath(const QString& path)
{
if (m_core == nullptr)
{
invokeMethodLater(this, &MediaViewCtrl::setPath, path);
return;
}

setMode(Mode::Unknown);

const QFileInfo pathInfo(path);
Expand Down
4 changes: 2 additions & 2 deletions src/gui/desktop/quick_items/media_view_ctrl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class MediaViewCtrl: public QObject
private:
safe_callback_ctrl m_callbackCtrl;
QUrl m_path;
Mode m_mode;
ICoreFactoryAccessor* m_core;
Mode m_mode = Mode::Unknown;
ICoreFactoryAccessor* m_core = nullptr;
Photo::Id m_id;

void setPath(const QString &);
Expand Down

0 comments on commit b43b8e1

Please sign in to comment.