Fix various layer-box-related RTEs

Sorry for anyone who had crashes because of this; many random layer box
bugs should be resolved by this commit.