Checking of parent->treeType is before if( parent ) which leads to crash when parent == nullptr.
parent->treeType
if( parent )
parent == nullptr