Page 1 of 1

ScriptedEvent "AddedChild" not fired during loadWindowLayout

Posted: Mon Feb 18, 2013 18:35
by marvinx
Hi,

I've written a simple window *.layout which defines a DefaultWindow (used as GUISheet) with two custom child widgets; see the pasted XML code below. For the main window I use two handlers for "AddedChild" and "RemovedChild" events. The problem I've encountered is as follows. When I load this layout (as a part of my Lua main script), then only the "RemovedChild" handler gets called, but --not-- the "AddedChild" event handler. It seems (for me) that during loadWindowLayout() no "AddedChild" events are fired ?!

I need these two events to perform some specific actions after a new child widget was added/removed to/from the main window.

Thanks for any help in advance!

==============================================
<GUILayout>

<Window Type="DefaultWindow" Name="Root">

<!-- Main window properties -->

<Property Name="UnifiedSize" Value="{{1,0},{1,0}}" />
<Property Name="MousePassThroughEnabled" value="True" />

<!-- Import NodeWidget layouts and create child nodes -->

<LayoutImport Filename="SensorNode.layout" Prefix="SNS_1" />
<LayoutImport Filename="SensorNode.layout" Prefix="SNS_2" />
<LayoutImport Filename="ActorNode.layout" Prefix="ACT_1" />

<!-- Scripted Events and handlers -->

<Event Name="AddedChild" Function="OnChildWindow_added" />
<Event Name="RemovedChild" Function="OnChildWindow_removed" />

</Window>

</GUILayout>
=========================================================

Re: ScriptedEvent "AddedChild" not fired during loadWindowLa

Posted: Tue Feb 19, 2013 09:28
by CrazyEddie
The issue here is the order in which the tags are processed. By the time the Event tags are reached - and therefore the event subscriptions made - the imported layouts are already added, thus no events are fired. The worst thing is that this sequence is mandated by the .xsd schema - with hindsight, this is clearly a mistake.

If you're not using xerces-c++ as your XML parser, will never use xerces-c++ as your XML parser and know that none of your target users will ever use xerces-c++ as the XML parser, then you can re-order the elements so that the event subscriptions happen first, and the events should then fire as you expect. If you can't guarantee that xerces-c++ will not be used when loading your files, there is no real fix currently (because xerces-c++ will throw an exception when it detects the tags in the 'wrong' sequence).

I have raised a ticket on our mantis tracker so that this requirement when using xerces-c++ can be relaxed in the future.

CE

Re: ScriptedEvent "AddedChild" not fired during loadWindowLa

Posted: Tue Feb 19, 2013 11:34
by marvinx
Thanks for this comprehensive answer!! Re-ordering the XML elements in the layout does work for me, since I am using TinyXML parser for all of my projects. So I can go on :D .

Re: ScriptedEvent "AddedChild" not fired during loadWindowLa

Posted: Tue Feb 19, 2013 11:40
by Kulik
just a side note: TinyXML is probably the slowest and most memory hungry choice you can make :)

HTH

Re: ScriptedEvent "AddedChild" not fired during loadWindowLa

Posted: Tue Feb 19, 2013 12:21
by marvinx
>> TinyXML is probably the slowest and most memory hungry choice you can make

Can you explain that in more detail? It would be interesting to know why TinyXML is not "tiny". What would be a more lightweight alternative? I originally planned to use RapidXML as CEGUI default parser module, but then I chose TinyXML (I can't remember why).

Re: ScriptedEvent "AddedChild" not fired during loadWindowLa

Posted: Tue Feb 19, 2013 13:28
by Kulik

Re: ScriptedEvent "AddedChild" not fired during loadWindowLa

Posted: Tue Feb 19, 2013 14:20
by marvinx
I think I should eventually switch to CEGUI's RapidXML parser module :roll: Its also interesting to see the poor performance of irrXML in this benchmark, compared to what it's supposed be according to http://www.ambiera.com/irrxml/

Thanks a lot for posting the link!