Page 1 of 1

[B2.1b] ManiaScript: Side effects of GetClassChildren()

Posted: 30 Jan 2013, 18:58
by m4rcel
There is an unwanted side effect of using GetClassChildren() multiple times, which lead to Runtime Errors. See the following Manialink:

Code: Select all

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<manialink>
	<quad id="quad" class="quad" />
	<script><!--
		
main() {
	declare CMlControl[] Array;
	Page.GetClassChildren("quad", Page.MainFrame, True);
	foreach (C in Page.GetClassChildren_Result) {
		Array.add(C);
	}
	log(Array); // Logs: [(CGameManialinkControl*)#SOMEID]
	Page.GetClassChildren("label", Page.MainFrame, True);
	log(Array); // Logs: [(CGameManialinkControl*)#Null] and throws Runtime error
}
--></script>
</manialink>
So from the first (non-empty) result of GetClassChildren, a local copy of the elements is created in Array. Yet after calling GetClassChildren() another time (returning an empty array in the example), it has the unexpected side effect to manipulate the elements of Array. This should not happen, Array must still contain the same Controls for later use.

Additionally accessing the element of the array (with log) throws the runtime error "Invalid access to parameter (Null object or elem not found in array) : Page.GetClassChildren_Result[0]". But I think the side effect of the GetClassChildren() is the real cause.