Fix potential crash in restorePreviousVideoMode()

We did get a crash upload about it. And indeed, the display and/or mode
list can asynchronously change, making these IDs invalid. Verify them
before doing anything. The "correct" fix would probably be getting rid
of these IDs, but this will have to wait for later.

Also, the DisplayManager::isValid* methods erroneously accepted negative
IDs as valid, which is definitely wrong. (No, the QMap.size method does
not return an unsigned integer either.)
This commit is contained in:
Vincent Lang 2015-10-22 13:47:14 +02:00
parent 6b105231ab
commit b2e23d7c53
2 changed files with 4 additions and 4 deletions

View File

@ -193,7 +193,7 @@ bool DisplayComponent::restorePreviousVideoMode()
if (!m_displayManager)
return false;
if (m_lastVideoMode < 0 || m_lastDisplay < 0)
if (!m_displayManager->isValidDisplayMode(m_lastDisplay, m_lastVideoMode))
return false;
bool ret = true;

View File

@ -61,13 +61,13 @@ DMVideoModePtr DisplayManager::getCurrentVideoMode(int display)
}
///////////////////////////////////////////////////////////////////////////////////////////////////
bool DisplayManager::isValidDisplay(int display) { return display < displays.size(); }
bool DisplayManager::isValidDisplay(int display) { return display >= 0 && display < displays.size(); }
///////////////////////////////////////////////////////////////////////////////////////////////////
bool DisplayManager::isValidDisplayMode(int display, int mode)
{
if (display < displays.size())
if (displays[display]->videoModes.size() > mode)
if (isValidDisplay(display))
if (mode >= 0 && mode < displays[display]->videoModes.size())
return true;
return false;