mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-09 04:32:51 +00:00
SystemMonitor: Fallback to invalid model index if there's no main thread
In the process model we check the thread with tid=pid to figure out the main thread of a process. This is used to construct the process view tree with non-main threads listed as children of the process row. However, there are sometimes circumstances where there is no main thread, even though the process should have been removed from the internal list by then. As a safe fallback, let's default to an invalid model index if we can't figure out what the main thread of a process is.
This commit is contained in:
parent
0f6e1f7a32
commit
bafaff61c9
Notes:
sideshowbarker
2024-07-17 18:46:57 +09:00
Author: https://github.com/kleinesfilmroellchen
Commit: bafaff61c9
Pull-request: https://github.com/SerenityOS/serenity/pull/13540
Issue: https://github.com/SerenityOS/serenity/issues/13542
2 changed files with 8 additions and 4 deletions
|
@ -344,7 +344,9 @@ GUI::ModelIndex ProcessModel::index(int row, int column, GUI::ModelIndex const&
|
|||
if (row >= static_cast<int>(m_processes.size()))
|
||||
return {};
|
||||
auto corresponding_thread = m_processes[row].main_thread();
|
||||
return create_index(row, column, corresponding_thread.ptr());
|
||||
if (!corresponding_thread.has_value())
|
||||
return {};
|
||||
return create_index(row, column, corresponding_thread.release_value().ptr());
|
||||
}
|
||||
// Thread under process.
|
||||
auto const& parent_thread = *static_cast<Thread const*>(parent.internal_data());
|
||||
|
@ -375,8 +377,10 @@ GUI::ModelIndex ProcessModel::parent_index(GUI::ModelIndex const& index) const
|
|||
return {};
|
||||
// FIXME: We can't use first_matching here (not even a const version) because Optional cannot contain references.
|
||||
auto const& parent = thread.current_state.process;
|
||||
if (!parent.main_thread().has_value())
|
||||
return {};
|
||||
|
||||
return create_index(m_processes.find_first_index(parent).release_value(), index.column(), parent.main_thread().ptr());
|
||||
return create_index(m_processes.find_first_index(parent).release_value(), index.column(), parent.main_thread().value().ptr());
|
||||
}
|
||||
|
||||
Vector<GUI::ModelIndex> ProcessModel::matches(StringView searching, unsigned flags, GUI::ModelIndex const&)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue