Ticket #2007: CGuiManager.patch

File CGuiManager.patch, 3.7 KB (added by Jorma Rebane, 11 years ago)

Change the tickobjects loop to use indices instead of iterators.

  • gui/GUIManager.cpp

     
    117117    page.gui.reset(new CGUI());
    118118    page.gui->Initialize();
    119119
    120     VfsPath path = VfsPath("gui") / page.name;
     120    VfsPath guiPath("gui");
     121    VfsPath path = guiPath / page.name;
    121122    page.inputs.insert(path);
    122123
    123124    CXeromyces xero;
     
    136137        return;
    137138    }
    138139
     140    // @note 2013.06.26 - pulled this outside the loop so it acts like a proper buffer
     141    CStrW name;
     142
    139143    XERO_ITER_EL(root, node)
    140144    {
    141145        if (node.GetNodeName() != elmt_include)
     
    144148            continue;
    145149        }
    146150
    147         CStrW name (node.GetText().FromUTF8());
     151        node.GetTextW(name);
    148152
    149153        PROFILE2("load gui xml");
    150154        PROFILE2_ATTR("name: %ls", name.c_str());
    151155
    152156        TIMER(name.c_str());
    153         VfsPath path = VfsPath("gui") / name;
     157        path = guiPath / name;
    154158        page.gui->LoadXmlFile(path, page.inputs);
    155159    }
    156160
     
    171175
    172176Status CGUIManager::ReloadChangedFiles(const VfsPath& path)
    173177{
    174     for (PageStackType::iterator it = m_PageStack.begin(); it != m_PageStack.end(); ++it)
     178    PageStackType::iterator end = m_PageStack.end();
     179    for (PageStackType::iterator it = m_PageStack.begin(); it != end; ++it)
    175180    {
    176181        if (it->inputs.count(path))
    177182        {
     
    261266{
    262267    PROFILE3("gui tick");
    263268
    264     // Save an immutable copy so iterators aren't invalidated by tick handlers
    265     PageStackType pageStack = m_PageStack;
    266 
    267     for (PageStackType::iterator it = pageStack.begin(); it != pageStack.end(); ++it)
     269    // @note Using i to avoid iterator invalidation when scripts PushPage/SwitchPage
     270    // @note Need to always check m_PageStack.size()
     271    for (int i = 0; i < m_PageStack.size(); ++i)
    268272    {
    269         m_CurrentGUI = it->gui;
    270         it->gui->TickObjects();
     273        m_CurrentGUI = m_PageStack[i].gui;
     274        m_CurrentGUI->TickObjects();
    271275    }
    272276    m_CurrentGUI.reset();
    273277}
     
    276280{
    277281    PROFILE3_GPU("gui");
    278282
    279     for (PageStackType::iterator it = m_PageStack.begin(); it != m_PageStack.end(); ++it)
     283    PageStackType::iterator end = m_PageStack.end();
     284    for (PageStackType::iterator it = m_PageStack.begin(); it != end; ++it)
    280285        it->gui->Draw();
    281286}
    282287
    283288void CGUIManager::UpdateResolution()
    284289{
    285     for (PageStackType::iterator it = m_PageStack.begin(); it != m_PageStack.end(); ++it)
     290    PageStackType::iterator end = m_PageStack.end();
     291    for (PageStackType::iterator it = m_PageStack.begin(); it != end; ++it)
    286292        it->gui->UpdateResolution();
    287293}
    288294
  • ps/XML/XeroXMB.cpp

     
    199199    if (m_Pointer == NULL || *(int*)(m_Pointer + 20) == 0)
    200200        return CStr8();
    201201
     202    // @note - This is really nasty stuff. Should read up on: http://www.joelonsoftware.com/articles/Unicode.html
    202203    return CStrW(utf16string((utf16_t*)(m_Pointer + 28))).ToUTF8();
    203204}
    204205
     206void XMBElement::GetTextW(CStrW& out) const
     207{
     208    // Return empty string if there's no text
     209    if (m_Pointer == NULL || *(int*)(m_Pointer + 20) == 0)
     210    {
     211        out.clear();
     212        return;
     213    }
     214    out = CStrW(utf16string((utf16_t*)(m_Pointer + 28)));
     215}
     216
    205217int XMBElement::GetLineNumber() const
    206218{
    207219    // Make sure there actually was some text to record the line of
  • ps/XML/XeroXMB.h

     
    179179    XMBElementList GetChildNodes() const;
    180180    XMBAttributeList GetAttributes() const;
    181181    CStr8 GetText() const;
     182    void GetTextW(CStrW& out) const;
    182183    // Returns the line number of the text within this element,
    183184    // or -1 if there is no text
    184185    int GetLineNumber() const;