Tracker: Don't crash clicking Open with... menu item
This bug was introduced in hrev47498 The reason Tracker crashed was because OpenWithContainerWindow had a NULL TargetModel() which we were trying to dereference. Fix this by creating an empty model in OpenWithContainerWindow. Add an ASSERT to check that the TargetModel() is not NULL in the future. Another way to fix this bug would have been to check that TargetModel() wasn't NULL each time before we use it. I didn't go with that solution because we assume TargetModel() is not NULL in a lot of places so it would be a lot of work to check them all. I think it's better to give OpenWithContainerWindow a dummy model even though it doesn't make sense for it to have one just so that we don't crash when we try to dereference the pointer.
This commit is contained in:
parent
bb804d092e
commit
b992df8968
@ -2906,6 +2906,9 @@ BContainerWindow::AddWindowContextMenus(BMenu* menu)
|
||||
// since we check view mode before display, this should be a radio
|
||||
// mode menu
|
||||
|
||||
Model* targetModel = TargetModel();
|
||||
ASSERT(targetModel != NULL);
|
||||
|
||||
bool needSeparator = true;
|
||||
if (IsTrash()) {
|
||||
menu->AddItem(new BMenuItem(B_TRANSLATE("Empty Trash"),
|
||||
@ -2913,7 +2916,7 @@ BContainerWindow::AddWindowContextMenus(BMenu* menu)
|
||||
} else if (IsPrintersDir()) {
|
||||
menu->AddItem(new BMenuItem(B_TRANSLATE("Add printer" B_UTF8_ELLIPSIS),
|
||||
new BMessage(kAddPrinter), 'N'));
|
||||
} else if (InTrash() || TargetModel()->IsRoot()) {
|
||||
} else if (InTrash() || targetModel->IsRoot()) {
|
||||
needSeparator = false;
|
||||
} else {
|
||||
TemplatesMenu* templatesMenu = new TemplatesMenu(PoseView(),
|
||||
@ -2945,7 +2948,7 @@ BContainerWindow::AddWindowContextMenus(BMenu* menu)
|
||||
new BMessage(kOpenParentDir), B_UP_ARROW));
|
||||
}
|
||||
|
||||
if (TargetModel()->IsRoot()) {
|
||||
if (targetModel->IsRoot()) {
|
||||
menu->AddSeparatorItem();
|
||||
menu->AddItem(new MountMenu(B_TRANSLATE("Mount")));
|
||||
}
|
||||
|
@ -540,7 +540,7 @@ OpenWithContainerWindow::SetCanOpen(bool on)
|
||||
|
||||
OpenWithPoseView::OpenWithPoseView(BRect frame, uint32 resizeMask)
|
||||
:
|
||||
BPoseView(0, frame, kListMode, resizeMask),
|
||||
BPoseView(new Model(), frame, kListMode, resizeMask),
|
||||
fHaveCommonPreferredApp(false),
|
||||
fIterator(NULL)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user