Guard against bad events in screen module
It can happen that the DisplayObserver methods are called without a valid Display object passed.
This commit is contained in:
parent
0933a7d1b2
commit
3d858bee95
1 changed files with 10 additions and 2 deletions
|
@ -86,13 +86,21 @@ void Screen::OnDisplayAdded(const gfx::Display& new_display) {
|
|||
}
|
||||
|
||||
void Screen::OnDisplayRemoved(const gfx::Display& old_display) {
|
||||
displays_.erase(FindById(&displays_, old_display.id()));
|
||||
auto iter = FindById(&displays_, old_display.id());
|
||||
if (iter == displays_.end())
|
||||
return;
|
||||
|
||||
displays_.erase(iter);
|
||||
Emit("display-removed", old_display);
|
||||
}
|
||||
|
||||
void Screen::OnDisplayMetricsChanged(const gfx::Display& display,
|
||||
uint32_t changed_metrics) {
|
||||
*FindById(&displays_, display.id()) = display;
|
||||
auto iter = FindById(&displays_, display.id());
|
||||
if (iter == displays_.end())
|
||||
return;
|
||||
|
||||
*iter = display;
|
||||
Emit("display-metrics-changed", display, MetricsToArray(changed_metrics));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue