-
Notifications
You must be signed in to change notification settings - Fork 149
fix: prevent crashes and memory leaks during object lifecycle #3168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,9 +3,10 @@ | |
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
| #include "dccobject.h" | ||
|
|
||
| #include "dccapp.h" | ||
| #include "dccobject_p.h" | ||
|
|
||
| #include <QLoggingCategory> | ||
| #include <QQmlContext> | ||
| #include <QQmlEngine> | ||
| #include <QQuickItem> | ||
|
|
@@ -45,7 +46,7 @@ | |
| m_page->deleteLater(); | ||
| m_page = nullptr; | ||
| } | ||
| if (m_parent) { | ||
| if (m_parent && m_parent->p_ptr) { | ||
| m_parent->p_ptr->removeChild(q_ptr); | ||
| } | ||
| while (!m_children.isEmpty()) { | ||
|
|
@@ -177,7 +178,7 @@ | |
|
|
||
| int DccObject::Private::getIndex() const | ||
| { | ||
| return m_parent ? m_parent->p_ptr->getChildren().indexOf(q_ptr) : -1; | ||
| return (m_parent && m_parent->p_ptr) ? m_parent->p_ptr->getChildren().indexOf(q_ptr) : -1; | ||
| } | ||
|
|
||
| DccObject *DccObject::Private::getChild(int childPos) const | ||
|
|
@@ -295,7 +296,7 @@ | |
| { | ||
| if (p_ptr->m_weight != weight) { | ||
| p_ptr->m_weight = weight; | ||
| if (p_ptr->m_parent) { | ||
| if (p_ptr->m_parent && p_ptr->m_parent->p_ptr) { | ||
| p_ptr->m_parent->p_ptr->updatePos(this); | ||
| } | ||
| Q_EMIT weightChanged(p_ptr->m_weight); | ||
|
|
@@ -442,11 +443,16 @@ | |
| void DccObject::setCurrentObject(DccObject *obj) | ||
| { | ||
| if (p_ptr->m_currentObject != obj) { | ||
| if (p_ptr->m_currentObject) { | ||
| Q_EMIT p_ptr->m_currentObject->deactive(); | ||
| } | ||
| DccObject *oldObject = p_ptr->m_currentObject; | ||
| p_ptr->m_currentObject = obj; | ||
| Q_EMIT currentObjectChanged(p_ptr->m_currentObject); | ||
|
|
||
| DccApp *app = DccApp::instance(); | ||
|
Comment on lines
+446
to
+449
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): Reordered deactivation vs. current object update may introduce behavior changes in slots. Previously, |
||
| if (!app || !app->isBatchUpdating()) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 看下ai的评论,另外app为空不需要执行了吧, |
||
| if (oldObject) { | ||
| Q_EMIT oldObject->deactive(); | ||
| } | ||
| Q_EMIT currentObjectChanged(p_ptr->m_currentObject); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -151,6 +151,13 @@ void LoadPluginTask::createData() | |
| soObj->setParent(nullptr); | ||
| } | ||
| } | ||
| if (m_pManager->isDeleting()) { | ||
| if (dataObj) | ||
| delete dataObj; | ||
| if (soObj) | ||
| delete soObj; | ||
| return; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 直接return,不走 这个正常么, Q_EMIT m_pManager->updatePluginStatus(m_data, DataEnd, ": create data finished. elapsed time :" + QString::number(timer.elapsed())); |
||
| } | ||
| if (dataObj) { | ||
| m_data->data = dataObj; | ||
| } | ||
|
|
@@ -507,6 +514,7 @@ void PluginManager::loadMain(PluginData *plugin) | |
| void PluginManager::createModule(QQmlComponent *component) | ||
| { | ||
| if (isDeleting()) { | ||
| component->deleteLater(); | ||
| return; | ||
| } | ||
| PluginData *plugin = component->property("PluginData").value<PluginData *>(); | ||
|
|
@@ -536,6 +544,7 @@ void PluginManager::createModule(QQmlComponent *component) | |
| void PluginManager::createMain(QQmlComponent *component) | ||
| { | ||
| if (isDeleting()) { | ||
| component->deleteLater(); | ||
| return; | ||
| } | ||
| PluginData *plugin = component->property("PluginData").value<PluginData *>(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这应该是在主线程里被触发的吧,是线性的吧,会存在多个交叉被setCurrentObject么,