From 7cd8ae4b8e91948f8465b607fe63bb013cdac076 Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Sun, 16 Sep 2012 11:38:45 +0200 Subject: [PATCH] Add safety checks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- Frameworks/DocumentWindow/src/DocumentController.mm | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Frameworks/DocumentWindow/src/DocumentController.mm b/Frameworks/DocumentWindow/src/DocumentController.mm index e5bed6d1..ba550342 100644 --- a/Frameworks/DocumentWindow/src/DocumentController.mm +++ b/Frameworks/DocumentWindow/src/DocumentController.mm @@ -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 map;