Skip to content

Commit

Permalink
Clearer error messages when failing to load external images
Browse files Browse the repository at this point in the history
  • Loading branch information
jlblancoc committed Dec 30, 2021
1 parent a55c995 commit 57be9f8
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 14 deletions.
74 changes: 60 additions & 14 deletions apps/RawLogViewer/main_show_selected_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,18 @@ void xRawLogViewerFrame::SelectObjectInTreeView(
if (classID->derivedFrom(CLASS_ID(CObservation)))
{
CObservation::Ptr obs(std::dynamic_pointer_cast<CObservation>(sel_obj));
obs->load();
obs->getDescriptionAsText(cout);
textDescriptionDone = true;

try
{
obs->load();
obs->getDescriptionAsText(cout);
textDescriptionDone = true;
}
catch (const mrpt::img::CExceptionExternalImageNotFound& e)
{
std::cout << "Error with lazy-load object:\n" << e.what() << "\n";
}

curSelectedObservation =
std::dynamic_pointer_cast<CObservation>(sel_obj);
}
Expand Down Expand Up @@ -348,16 +357,33 @@ void xRawLogViewerFrame::SelectObjectInTreeView(

// Get bitmap:
// ----------------------
wxImage* img = mrpt::gui::MRPTImage2wxImage(obs->image);
bmpObsImage->SetBitmap(wxBitmap(*img));
bmpObsImage->SetSize(img->GetWidth(), img->GetHeight());
bool loadOk = false;
try
{
obs->load();
loadOk = true;
}
catch (const std::exception& e)
{
std::cout << "Error with lazy-load image:\n" << e.what() << "\n";
}

if (loadOk)
{
wxImage* img = mrpt::gui::MRPTImage2wxImage(obs->image);
bmpObsImage->SetBitmap(wxBitmap(*img));
bmpObsImage->SetSize(img->GetWidth(), img->GetHeight());
delete img;
}
else
{
bmpObsImage->SetBitmap(wxBitmap());
}

FlexGridSizerImg->FitInside(ScrolledWindow2);
// bmpObsImage->FitInside();
// ScrolledWindow2->SetVirtualSize(img->GetWidth(), img->GetHeight());
ScrolledWindow2->SetScrollRate(1, 1);

bmpObsImage->Refresh();
delete img;
obs->image.unload(); // For externally-stored datasets
}

Expand All @@ -369,19 +395,37 @@ void xRawLogViewerFrame::SelectObjectInTreeView(
Notebook1->ChangeSelection(4);
auto obs = std::dynamic_pointer_cast<CObservationStereoImages>(sel_obj);

bool loadOk = false;
try
{
obs->load();
loadOk = true;
}
catch (const std::exception& e)
{
std::cout << "Error with lazy-load image:\n" << e.what() << "\n";
}

// Images:
// ----------------------
wxImage* imgLeft = mrpt::gui::MRPTImage2wxImage(obs->imageLeft);
bmpObsStereoLeft->SetBitmap(wxBitmap(*imgLeft));
bmpObsStereoLeft->Refresh();
delete imgLeft;
if (loadOk)
{
wxImage* imgLeft = mrpt::gui::MRPTImage2wxImage(obs->imageLeft);
bmpObsStereoLeft->SetBitmap(wxBitmap(*imgLeft));
bmpObsStereoLeft->Refresh();
delete imgLeft;

if (obs->hasImageRight)
obs->imageLeft.unload(); // For externally-stored datasets
}

if (obs->hasImageRight && loadOk)
{
wxImage* imgRight = mrpt::gui::MRPTImage2wxImage(obs->imageRight);
bmpObsStereoRight->SetBitmap(wxBitmap(*imgRight));
bmpObsStereoRight->Refresh();
delete imgRight;

obs->imageRight.unload(); // For externally-stored datasets
}

if (obs->hasImageDisparity)
Expand All @@ -391,6 +435,8 @@ void xRawLogViewerFrame::SelectObjectInTreeView(
bmpObsStereoDisp->SetBitmap(wxBitmap(*imgDisp));
bmpObsStereoDisp->Refresh();
delete imgDisp;

obs->imageDisparity.unload(); // For externally-stored datasets
}
}

Expand Down
3 changes: 3 additions & 0 deletions doc/source/doxygen-docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# Version 2.4.1: UNRELEASED
- Changes in build system:
- Disable -flto in nanogui (to avoid an [Eigen regression](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1000780)).
- Changes in applications:
- RawlogViewer:
- Better handling of exceptions failing to load delayed-load images.
- Changes in libraries:
- \ref mrpt_core_grp
- Remove unused header `<mrpt/3rdparty/llvm/propagate_const.h>`.
Expand Down

0 comments on commit 57be9f8

Please sign in to comment.