Skip to content
Browse files

[extendedprogressbar] refactor UpdateState to ensure m_iCurrentItem i…

…s always valid, so that we don't close the dialog prematurely
  • Loading branch information...
1 parent 465f2eb commit a9c96f94b53b00efb42958251a33ed804daac4a0 Jonathan Marshall committed Nov 17, 2012
Showing with 22 additions and 31 deletions.
  1. +22 −31 xbmc/dialogs/GUIDialogExtendedProgressBar.cpp
View
53 xbmc/dialogs/GUIDialogExtendedProgressBar.cpp
@@ -110,7 +110,6 @@ void CGUIDialogExtendedProgressBar::Process(unsigned int currentTime, CDirtyRegi
void CGUIDialogExtendedProgressBar::UpdateState(unsigned int currentTime)
{
- bool bNoItemsLeft(false);
string strHeader;
string strTitle;
float fProgress(-1.0f);
@@ -125,13 +124,19 @@ void CGUIDialogExtendedProgressBar::UpdateState(unsigned int currentTime)
{
delete m_handles.at(iPtr);
m_handles.erase(m_handles.begin() + iPtr);
-
- // current item deleted, back one
- if ((int)m_iCurrentItem == iPtr && m_iCurrentItem > 0)
- m_iCurrentItem--;
}
}
+ if (!m_handles.size())
+ {
+ Close(true, 0, true, false);
+ return;
+ }
+
+ // ensure the current item is in our range
+ if (m_iCurrentItem >= m_handles.size())
+ m_iCurrentItem = m_handles.size() - 1;
+
// update the current item ptr
if (currentTime > m_iLastSwitchTime &&
currentTime - m_iLastSwitchTime >= ITEM_SWITCH_TIME_MS)
@@ -143,36 +148,22 @@ void CGUIDialogExtendedProgressBar::UpdateState(unsigned int currentTime)
m_iCurrentItem = 0;
}
- if (m_iCurrentItem < m_handles.size())
+ CGUIDialogProgressBarHandle *handle = m_handles.at(m_iCurrentItem);
+ if (handle)
{
- CGUIDialogProgressBarHandle *handle = m_handles.at(m_iCurrentItem);
- if (handle)
- {
- strTitle = handle->Text();
- strHeader = handle->Title();
- fProgress = handle->Percentage();
- }
- }
- else
- {
- bNoItemsLeft = true;
+ strTitle = handle->Text();
+ strHeader = handle->Title();
+ fProgress = handle->Percentage();
}
}
- if (bNoItemsLeft)
- {
- Close(true, 0, true, false);
- }
- else
- {
- SET_CONTROL_LABEL(CONTROL_LABELHEADER, strHeader);
- SET_CONTROL_LABEL(CONTROL_LABELTITLE, strTitle);
+ SET_CONTROL_LABEL(CONTROL_LABELHEADER, strHeader);
+ SET_CONTROL_LABEL(CONTROL_LABELTITLE, strTitle);
- if (fProgress > -1.0f)
- {
- SET_CONTROL_VISIBLE(CONTROL_PROGRESS);
- CGUIProgressControl* pProgressCtrl=(CGUIProgressControl*)GetControl(CONTROL_PROGRESS);
- if (pProgressCtrl) pProgressCtrl->SetPercentage(fProgress);
- }
+ if (fProgress > -1.0f)
+ {
+ SET_CONTROL_VISIBLE(CONTROL_PROGRESS);
+ CGUIProgressControl* pProgressCtrl=(CGUIProgressControl*)GetControl(CONTROL_PROGRESS);
+ if (pProgressCtrl) pProgressCtrl->SetPercentage(fProgress);
}
}

0 comments on commit a9c96f9

Please sign in to comment.
Something went wrong with that request. Please try again.