Skip to content

Commit d332c8d

Browse files
committed
fix: prevent crash when treeland restarts in taskbar
The crash occurs because when treeland restarts, the clear() method in TreeLandWindowMonitor clears internal window lists but fails to reset the tracked windows model. When treeland restart triggers a cleanup followed by re-initialization, the model still holds stale references to windows that have been destroyed, leading to a use-after-free crash when the model attempts to access the window data during view updates. Added clearTrackedWindows() method to properly clear all tracked windows from the model using beginResetModel/endResetModel, and called it at the start of clear() in both TreeLandWindowMonitor and X11WindowMonitor to ensure the model is reset before internal lists are cleared. This ensures the model and view are properly synchronized, preventing access to destroyed window objects. Log: fix treeland restart crash Influence: 1. Test taskbar behavior when treeland restarts unexpectedly 2. Verify taskbar shows correct windows after treeland restart 3. Test taskbar with no windows open during treeland restart 4. Verify no crash when multiple rapid treeland restarts occur 5. Test X11 window monitor clear function for regressions 6. Verify taskbar preview windows still work correctly after restart fix: 修复任务栏在treeland重启时崩溃的问题 当treeland重启时,TreeLandWindowMonitor中的clear()方法清除了内部窗口列 表,但未能重置跟踪窗口的模型。treeland重启触发清理后重新初始化时,模型 仍然持有已被销毁窗口的陈旧引用,导致视图更新时访问已释放的窗口对象引发崩 溃。新增clearTrackedWindows()方法,通过beginResetModel/endResetModel正确 清除模型中的所有跟踪窗口,并在TreeLandWindowMonitor和X11WindowMonitor的 clear()方法开始时调用该方法,确保在清除内部列表之前重置模型。这保证了模 型和视图同步一致,防止访问已销毁的窗口对象。 Log: 修复treeland重启崩溃问题 Influence: 1. 测试treeland异常重启时任务栏的行为 2. 验证treeland重启后任务栏显示正确的窗口 3. 测试treeland重启时没有打开任何窗口的情况 4. 验证多次快速重启treeland不会导致崩溃 5. 测试X11窗口监视器的清除功能是否有回归问题 6. 验证重启后任务栏预览窗口仍然正常工作
1 parent e25ffed commit d332c8d

4 files changed

Lines changed: 11 additions & 0 deletions

File tree

panels/dock/taskmanager/abstractwindowmonitor.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,5 +158,13 @@ void AbstractWindowMonitor::destroyWindow(AbstractWindow * window)
158158
endRemoveRows();
159159
}
160160

161+
void AbstractWindowMonitor::clearTrackedWindows()
162+
{
163+
if (m_trackedWindows.isEmpty())
164+
return;
161165

166+
beginResetModel();
167+
m_trackedWindows.clear();
168+
endResetModel();
169+
}
162170
}

panels/dock/taskmanager/abstractwindowmonitor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class AbstractWindowMonitor : public QAbstractListModel, public AbstractTaskMana
2626

2727
void trackWindow(AbstractWindow* window);
2828
void destroyWindow(AbstractWindow * window);
29+
void clearTrackedWindows();
2930

3031
AbstractWindowMonitor(QObject* parent = nullptr);
3132
virtual void start() = 0;

panels/dock/taskmanager/treelandwindowmonitor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ void TreeLandWindowMonitor::stop()
102102

103103
void TreeLandWindowMonitor::clear()
104104
{
105+
clearTrackedWindows();
105106
m_windows.clear();
106107
m_dockPreview.reset(nullptr);
107108
updateFullscreenState();

panels/dock/taskmanager/x11windowmonitor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ void X11WindowMonitor::stop()
9191

9292
void X11WindowMonitor::clear()
9393
{
94+
clearTrackedWindows();
9495
m_windows.clear();
9596
m_windowPreview.reset(nullptr);
9697
}

0 commit comments

Comments
 (0)