Add safety checks

Since 10% of reported crashes are in synchronizeWindowTitle and seems to be about not having a proper document pointer, I am adding these checks and some debug output — don’t understand how we would get into this situation though.
This commit is contained in:
Allan Odgaard
2012-09-16 11:38:45 +02:00
parent 13ba42f98d
commit 7cd8ae4b8e

View File

@@ -506,7 +506,20 @@ OAK_DEBUG_VAR(DocumentController);
- (void)synchronizeWindowTitle
{
if(selectedTabIndex >= documentTabs.size())
{
fprintf(stderr, "*** error: selected tab out of bounds: %zu >= %zu\n", selectedTabIndex, documentTabs.size());
return;
}
document::document_ptr doc = [self selectedDocument];
if(!doc)
{
fprintf(stderr, "*** error: no document (synchronizeWindowTitle)\n");
return;
}
std::string docDirectory = doc->path() != NULL_STR ? path::parent(doc->path()) : to_s(self.untitledSavePath);
std::map<std::string, std::string> map;