Skip to content

Commit 45b0783

Browse files
committed
[gui] Avoid several crashes when the images are not found
Opening the classic browser when some pictures are missing causes crashes due to missing checks. With this PR the browser will simply not display the missing elements (and it still works somewhat fine) in such cases.
1 parent 805bf76 commit 45b0783

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

graf2d/x11/src/TGX11.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,8 @@ void TGX11::ClearPixmap(Drawable *pix)
420420

421421
void TGX11::ClearWindow()
422422
{
423+
if (!gCws) return;
424+
423425
if (!gCws->fIsPixmap && !gCws->fDoubleBuffer) {
424426
XSetWindowBackground((Display*)fDisplay, gCws->fDrawing, GetColor(0).fPixel);
425427
XClearWindow((Display*)fDisplay, gCws->fDrawing);

gui/gui/src/TGListTree.cxx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2551,7 +2551,7 @@ const TGGC &TGListTree::GetColorGC()
25512551
const TGPicture *TGListTree::GetOpenPic()
25522552
{
25532553
if (!fgOpenPic)
2554-
fgOpenPic = gClient->GetPicture("ofolder_t.xpm");
2554+
fgOpenPic = gClient->GetPictureOrEmpty("ofolder_t.xpm");
25552555
((TGPicture *)fgOpenPic)->AddReference();
25562556
return fgOpenPic;
25572557
}
@@ -2562,7 +2562,7 @@ const TGPicture *TGListTree::GetOpenPic()
25622562
const TGPicture *TGListTree::GetClosedPic()
25632563
{
25642564
if (!fgClosedPic)
2565-
fgClosedPic = gClient->GetPicture("folder_t.xpm");
2565+
fgClosedPic = gClient->GetPictureOrEmpty("folder_t.xpm");
25662566
((TGPicture *)fgClosedPic)->AddReference();
25672567
return fgClosedPic;
25682568
}
@@ -2573,7 +2573,7 @@ const TGPicture *TGListTree::GetClosedPic()
25732573
const TGPicture *TGListTree::GetCheckedPic()
25742574
{
25752575
if (!fgCheckedPic)
2576-
fgCheckedPic = gClient->GetPicture("checked_t.xpm");
2576+
fgCheckedPic = gClient->GetPictureOrEmpty("checked_t.xpm");
25772577
((TGPicture *)fgCheckedPic)->AddReference();
25782578
return fgCheckedPic;
25792579
}
@@ -2584,7 +2584,7 @@ const TGPicture *TGListTree::GetCheckedPic()
25842584
const TGPicture *TGListTree::GetUncheckedPic()
25852585
{
25862586
if (!fgUncheckedPic)
2587-
fgUncheckedPic = gClient->GetPicture("unchecked_t.xpm");
2587+
fgUncheckedPic = gClient->GetPictureOrEmpty("unchecked_t.xpm");
25882588
((TGPicture *)fgUncheckedPic)->AddReference();
25892589
return fgUncheckedPic;
25902590
}

gui/gui/src/TGTextEditor.cxx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ TGTextEditor::TGTextEditor(const char *filename, const TGWindow *p, UInt_t w,
240240
fToolBar->RemoveFrame(fComboCmd);
241241
fLabel->UnmapWindow();
242242
fToolBar->RemoveFrame(fLabel);
243-
fToolBar->GetButton(kM_FILE_EXIT)->SetState(kButtonDisabled);
243+
if (auto btn = fToolBar->GetButton(kM_FILE_EXIT); btn) btn->SetState(kButtonDisabled);
244244
fToolBar->Layout();
245245
}
246246
if (filename) {
@@ -412,10 +412,10 @@ void TGTextEditor::Build()
412412
AddFrame(new TGHorizontal3DLine(this),
413413
new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0,0,2,2));
414414

415-
fToolBar->GetButton(kM_EDIT_CUT)->SetState(kButtonDisabled);
416-
fToolBar->GetButton(kM_EDIT_COPY)->SetState(kButtonDisabled);
417-
fToolBar->GetButton(kM_EDIT_DELETE)->SetState(kButtonDisabled);
418-
fToolBar->GetButton(kM_EDIT_PASTE)->SetState(kButtonDisabled);
415+
if (auto btn = fToolBar->GetButton(kM_EDIT_CUT); btn) btn->SetState(kButtonDisabled);
416+
if (auto btn = fToolBar->GetButton(kM_EDIT_COPY); btn) btn->SetState(kButtonDisabled);
417+
if (auto btn = fToolBar->GetButton(kM_EDIT_DELETE); btn) btn->SetState(kButtonDisabled);
418+
if (auto btn = fToolBar->GetButton(kM_EDIT_PASTE); btn) btn->SetState(kButtonDisabled);
419419

420420
fTextEdit = new TGTextEdit(this, 10, 10, 1);
421421
if (gClient->GetStyle() < 2) {
@@ -866,8 +866,8 @@ Bool_t TGTextEditor::HandleTimer(TTimer *t)
866866
}
867867
else {
868868
fMenuEdit->EnableEntry(kM_EDIT_PASTE);
869-
if (fToolBar->GetButton(kM_EDIT_PASTE)->GetState() == kButtonDisabled)
870-
fToolBar->GetButton(kM_EDIT_PASTE)->SetState(kButtonUp);
869+
if (auto btn = fToolBar->GetButton(kM_EDIT_PASTE); btn && btn->GetState() == kButtonDisabled)
870+
btn->SetState(kButtonUp);
871871
}
872872
// check if text is selected in the editor
873873
if (fTextEdit->IsMarked()) {
@@ -884,8 +884,8 @@ Bool_t TGTextEditor::HandleTimer(TTimer *t)
884884
fMenuEdit->DisableEntry(kM_EDIT_CUT);
885885
fMenuEdit->DisableEntry(kM_EDIT_COPY);
886886
fMenuEdit->DisableEntry(kM_EDIT_DELETE);
887-
if (fToolBar->GetButton(kM_EDIT_CUT)->GetState() == kButtonUp) {
888-
fToolBar->GetButton(kM_EDIT_CUT)->SetState(kButtonDisabled);
887+
if (auto btn = fToolBar->GetButton(kM_EDIT_CUT); btn && btn->GetState() == kButtonUp) {
888+
btn->SetState(kButtonDisabled);
889889
fToolBar->GetButton(kM_EDIT_COPY)->SetState(kButtonDisabled);
890890
fToolBar->GetButton(kM_EDIT_DELETE)->SetState(kButtonDisabled);
891891
}

0 commit comments

Comments
 (0)