Check null for elements[i] in class CCNode?

Topics: Windows Phone 8
Nov 11, 2013 at 6:50 AM
Edited Nov 11, 2013 at 6:52 AM
Could I ignore to check null for elements[i] at this code (CCNode.Visit()) ?
// Draw the z >= 0 order children next.
if (elements[i] != null && elements[i].Visible)/* && elements[i].m_nZOrder >= 0*/
{
    elements[i].Visit();
}
instead of
// Draw the z >= 0 order children next.
if (elements[i].Visible)/* && elements[i].m_nZOrder >= 0*/
{
    elements[i].Visit();
}
Coordinator
Nov 16, 2013 at 9:49 PM
Hi,

no, you should not ignore the null check. We put the null checks in there when we find race conditions that cause these null values to occur in the child lists.

while it may work 90% of the time, you will find, one day, a seemingly random crash of your app from this null reference.