resolved the crash issue by adding a check that the treeitem returned from generateSegment != NULL