summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2017-04-18 16:45:58 +0200
committerPetr Mrázek <peterix@gmail.com>2017-04-18 16:45:58 +0200
commit5565a2f85e8b7a4b0e4758b5b6f4d806b964cf94 (patch)
treeeff9e090c9f2a7dd66feb04e08226f7e74017689 /api
parentc4c8e99681e14e5d0e82a13cb0631107dedf96ff (diff)
downloadMultiMC-5565a2f85e8b7a4b0e4758b5b6f4d806b964cf94.tar
MultiMC-5565a2f85e8b7a4b0e4758b5b6f4d806b964cf94.tar.gz
MultiMC-5565a2f85e8b7a4b0e4758b5b6f4d806b964cf94.tar.lz
MultiMC-5565a2f85e8b7a4b0e4758b5b6f4d806b964cf94.tar.xz
MultiMC-5565a2f85e8b7a4b0e4758b5b6f4d806b964cf94.zip
NOISSUE fix crash because of early destruction of java list load task
Diffstat (limited to 'api')
-rw-r--r--api/logic/java/JavaInstallList.cpp27
-rw-r--r--api/logic/java/JavaInstallList.h14
2 files changed, 36 insertions, 5 deletions
diff --git a/api/logic/java/JavaInstallList.cpp b/api/logic/java/JavaInstallList.cpp
index dbf66f5f..44ac861d 100644
--- a/api/logic/java/JavaInstallList.cpp
+++ b/api/logic/java/JavaInstallList.cpp
@@ -31,7 +31,27 @@ JavaInstallList::JavaInstallList(QObject *parent) : BaseVersionList(parent)
shared_qobject_ptr<Task> JavaInstallList::getLoadTask()
{
- return new JavaListLoadTask(this);
+ load();
+ return getCurrentTask();
+}
+
+shared_qobject_ptr<Task> JavaInstallList::getCurrentTask()
+{
+ if(m_status == Status::InProgress)
+ {
+ return m_loadTask;
+ }
+ return nullptr;
+}
+
+void JavaInstallList::load()
+{
+ if(m_status != Status::InProgress)
+ {
+ m_status = Status::InProgress;
+ m_loadTask = new JavaListLoadTask(this);
+ m_loadTask->start();
+ }
}
const BaseVersionPtr JavaInstallList::at(int i) const
@@ -41,7 +61,7 @@ const BaseVersionPtr JavaInstallList::at(int i) const
bool JavaInstallList::isLoaded()
{
- return m_loaded;
+ return m_status == JavaInstallList::Status::Done;
}
int JavaInstallList::count() const
@@ -87,7 +107,6 @@ void JavaInstallList::updateListData(QList<BaseVersionPtr> versions)
{
beginResetModel();
m_vlist = versions;
- m_loaded = true;
sortVersions();
if(m_vlist.size())
{
@@ -95,6 +114,8 @@ void JavaInstallList::updateListData(QList<BaseVersionPtr> versions)
best->recommended = true;
}
endResetModel();
+ m_status = Status::Done;
+ m_loadTask.reset();
}
bool sortJavas(BaseVersionPtr left, BaseVersionPtr right)
diff --git a/api/logic/java/JavaInstallList.h b/api/logic/java/JavaInstallList.h
index afc5ef43..934e588b 100644
--- a/api/logic/java/JavaInstallList.h
+++ b/api/logic/java/JavaInstallList.h
@@ -31,6 +31,12 @@ class JavaListLoadTask;
class MULTIMC_LOGIC_EXPORT JavaInstallList : public BaseVersionList
{
Q_OBJECT
+ enum class Status
+ {
+ NotDone,
+ InProgress,
+ Done
+ };
public:
explicit JavaInstallList(QObject *parent = 0);
@@ -47,9 +53,13 @@ public slots:
void updateListData(QList<BaseVersionPtr> versions) override;
protected:
- QList<BaseVersionPtr> m_vlist;
+ void load();
+ shared_qobject_ptr<Task> getCurrentTask();
- bool m_loaded = false;
+protected:
+ Status m_status = Status::NotDone;
+ shared_qobject_ptr<JavaListLoadTask> m_loadTask;
+ QList<BaseVersionPtr> m_vlist;
};
class JavaListLoadTask : public Task