numchildren++;
Box before = getChild(i);
- if (before == null) rootChild.peerTree_rightmost().insertAfterMe(b);
+ if (before == null) {
+ if (rootChild == null) rootChild = b;
+ else rootChild.peerTree_rightmost().insertAfterMe(b);
+ }
else before.insertBeforeMe(b);
// need both of these in case child was already uncalc'ed