Common runtime errors

From OTBWiki
Revision as of 18:36, 14 January 2009 by Julien (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This page is intended to describe common runtime errors encountered by developers as well as their possible causes.

Streaming and variable scope

If we consider the following case:

ViewerType::Pointer viewer = ViewerType::New();
if(use_overlay)
  {
     ReaderType::Pointer reader = ReaderType::New();
     reader->SetFileName(filename);
     viewer->SetInputOverlay(reader->GetOutput();
  }
viewer->Build();
viewer->Update();

The scope of the reader variable is limited to the brackets. Therefore, by the time viewer->Build() and viewer->Update() are called, the reader has already been deleted. Note that the reader output image still exists, thanks to reference counting and to viewer->SetInputOverlay(reader->GetOutput();. It is only unplugged from the reader. This will cause any attempt to update a new requested region of the image to fail, because it has no more source.