mirror of
https://github.com/electron/electron.git
synced 2026-01-23 14:28:17 -05:00
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:
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user