Changeset 386

Show
Ignore:
Timestamp:
09/19/11 11:23:04 (8 months ago)
Author:
Carsten
Message:

GuiSys:
Make sure that hierarchies of windows cannot have cycles.

This prevents the crash reported in #87, but doesn't fix its cause.
(A fix addressing the cause of the problem follows.)
References #87.

Location:
cafu/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • cafu/trunk/CaWE/GuiEditor/GuiDocument.cpp

    r367 r386  
    122122 
    123123 
    124 cf::GuiSys::WindowT* GuiDocumentT::FindWindowByName(const wxString& WindowName) 
    125 { 
    126     if (m_RootWindow->GetName()==WindowName) return m_RootWindow; 
    127  
    128     return m_RootWindow->Find(std::string(WindowName)); 
    129 } 
    130  
    131  
    132124void GuiDocumentT::SetSelection(const ArrayT<cf::GuiSys::WindowT*>& NewSelection) 
    133125{ 
  • cafu/trunk/CaWE/GuiEditor/GuiDocument.hpp

    r367 r386  
    5959        cf::GuiSys::GuiImplT* GetGui() { return m_Gui; } 
    6060        cf::GuiSys::WindowT* GetRootWindow() { return m_RootWindow; } 
    61         cf::GuiSys::WindowT* FindWindowByName(const wxString& WindowName); 
    6261 
    6362        GuiPropertiesT& GetGuiProperties() { return m_GuiProperties; } 
  • cafu/trunk/Libs/GuiSys/Window.cpp

    r373 r386  
    236236void WindowT::GetChildren(ArrayT<WindowT*>& Chld, bool Recurse) 
    237237{ 
     238#ifdef DEBUG 
     239    // Make sure that there are no cycles in the hierarchy of children. 
     240    for (unsigned long ChildNr=0; ChildNr<Children.Size(); ChildNr++) 
     241        assert(Chld.Find(Children[ChildNr]) == -1); 
     242#endif 
     243 
    238244    Chld.PushBack(Children); 
    239245 
     
    906912    WindowT* Child=(WindowT*)cf::GuiSys::GuiImplT::GetCheckedObjectParam(LuaState, 2, TypeInfo); 
    907913 
    908     if (Child->Parent!=NULL) 
     914    if (Child->Parent!=NULL)        // A child window must be a root node... 
    909915        return luaL_argerror(LuaState, 2, "child window already has a parent, use RemoveChild() first"); 
     916 
     917    if (Child==Win->GetRoot())      // ... but not the root of the hierarchy it is inserted into. 
     918        return luaL_argerror(LuaState, 2, "a window cannot be made a child of itself"); 
    910919 
    911920    Win->Children.PushBack(Child);