CrazyEddie wrote:Hi,
Thanks a lot for the heads-up on this. I'll make an appropriate fix to the code in SVN
CE.
IMHO it should be like:
System singleton has std::map<Window*, Window*> of items to be removed, call it m_WindowsToDestroy
system singlten has function DestroyWindow(Window* wnd) (like CreateWindow) which only do is adds this window to this list
And in renderGUI shoul look like this
void renderGUI()
{
// .. do render stuff and updating of windows
// clear m_WindowsToDestroy //do not forget to free each Window* //instance
}
I guess this solution will be better than just reorder counter, because you do not make any suggestions about user defined code - user want to remove window please remove it. But when you change order of index (not bad solution) but you suggest that user can remove window - and it is not bug fix but just bug hide - mine opinion.
And another argument is:
if some child window wants to remove not only self but two or more child windows of same parent we will have such situation - for example:
child_count = 10
i = 9
and this 9th window removes 2 windows in nex iteration we have child_count = 8 and i = 8 but 8 not less then 8 so left windows will not have update event.
So if you wish to destroy window - mine solution is good and another fature - to avoid some problems - user can not only remove child windows but also add them, so base class Window will have to maps -
std::map<Window*, Window> - m_WindowsToAdd and m_WindowsToRemove (from childs) and when it is being updated code will look like
update
{
// m_Childs.insert(m_WindowsToAdd.first(), m_WindowsToAdd.end())
//m_WindowsToAdd.clear();
// m_Childs.erase(m_WindowsToRemove.end(), m_WidnowsToRemove.end()) update stuff
//m_WindowsToRemove.clear() - possible destroy these windows
// update stuff
}
Also methods should be updated - getChild()
{
//seek in m_WindowsToAdd
//if not find
//{ Seek in m_Childs
}
if you are intrested - I will make some coding home and post here or send on email.
Forgive me for my bad english
Thank you.
Hope I was helpfull.