https://www.slicer.org/w/index.php?title=Documentation/4.1/Developers/Tutorials/Troubleshooting&feed=atom&action=historyDocumentation/4.1/Developers/Tutorials/Troubleshooting - Revision history2024-03-29T12:16:01ZRevision history for this page on the wikiMediaWiki 1.33.0https://www.slicer.org/w/index.php?title=Documentation/4.1/Developers/Tutorials/Troubleshooting&diff=32222&oldid=prevUpdateBot: Prepend documentation/versioncheck template. See http://na-mic.org/Mantis/view.php?id=28872013-06-14T07:22:55Z<p>Prepend documentation/versioncheck template. See http://na-mic.org/Mantis/view.php?id=2887</p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">Revision as of 07:22, 14 June 2013</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"><noinclude>{{documentation/versioncheck}}</noinclude></ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Here are some tips to narrow down various issues such as crash, or memory leaks</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Here are some tips to narrow down various issues such as crash, or memory leaks</div></td></tr>
</table>UpdateBothttps://www.slicer.org/w/index.php?title=Documentation/4.1/Developers/Tutorials/Troubleshooting&diff=27134&oldid=prevJChris.FillionR at 19:47, 16 June 20122012-06-16T19:47:58Z<p></p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">Revision as of 19:47, 16 June 2012</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del class="diffchange diffchange-inline">{{documentation/underconstruction}}</del></div></td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> </div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Here are some tips to narrow down various issues such as crash, or memory leaks</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Here are some tips to narrow down various issues such as crash, or memory leaks</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
</table>JChris.FillionRhttps://www.slicer.org/w/index.php?title=Documentation/4.1/Developers/Tutorials/Troubleshooting&diff=25571&oldid=prevJChris.FillionR: 4.0 -> 4.12012-04-12T04:44:40Z<p>4.0 -> 4.1</p>
<p><b>New page</b></p><div>{{documentation/underconstruction}}<br />
Here are some tips to narrow down various issues such as crash, or memory leaks<br />
<br />
=Disable features= <br />
Try running Slicer with as few features as possible:<br />
* Disable Slicer options via the command line<br />
*: <pre>$ ./Slicer --no-splash --ignore-slicerrc --disable-cli-module --disable-loadable-module --disable-scriptedmodule</pre><br />
** Look at all the possible options<br />
**: <pre>$ ./Slicer --help</pre><br />
* Disable ITK plugins<br />
*: CLI modules silently load the ITK plugins in lib/Slicer-4.0/ITKFactories. These plugins are used to share the volumes between Slicer and the ITK filter without having to copy them on disk. <br />
** rename lib/Slicer-4.0/ITKFactories into lib/Slicer-4.0/ITKFactories-disabled<br />
* Disable Qt plugins<br />
** rename lib/Slicer-4.0/iconengine into lib/Slicer-4.0/iconengine-disabled<br />
<br />
=Track memory leaks=<br />
<ol><br />
<li> Turn ON the VTK_DEBUG_LEAKS CMake variable and build Slicer</li><br />
<li> Create a test that reproduces the memory leak systematically </li><br />
After execution, the memory leaks are printed automatically by VTK on the standard output:<br />
224: vtkDebugLeaks has detected LEAKS!<br />
224: Class "vtkProperty2D" has 60 instances still around.<br />
...<br />
<li>Find what specific instance of a class (here vtkProperty2D) leaks.</li><br />
If the class is instantiated a large amount of time, it is hard to know what instance is leaking.<br />
You can edit the constructor and destructor of the class (here vtkProperty2D::vtkProperty2D() and vtkProperty2D::~vtkProperty2D())<br />
vtkProperty2D::vtkProperty2D()<br />
{<br />
...<br />
static int count = 0;<br />
std::cout << "CREATE vtkProperty2D instance #" << count++ << " " << this << std::endl;<br />
}<br />
<br />
vtkProperty2D::~vtkProperty2D()<br />
{<br />
...<br />
static int count = 0;<br />
std::cout << "DELETE vtkProperty2D instance #" << count++ << " " << this << std::endl;<br />
}<br />
Don't forget to rebuild VTK if the class is from VTK (and not just Slicer inner build)<br />
After running the test again, you should see a list of <br />
...<br />
CREATE vtkProperty2D instance #0 0x0123456<br />
...<br />
CREATE vtkProperty2D instance #1 0x01234E5<br />
...<br />
DELETE vtkProperty2D instance #0 0x0123456<br />
...<br />
DELETE vtkProperty2D instance #1 0x01234E5<br />
...<br />
CREATE vtkProperty2D instance #2 0x0123A23<br />
...<br />
CREATE vtkProperty2D instance #3 0x0124312<br />
...<br />
Copy/paste the listing in a text editor and ensure that for each CREATE of a pointer (e.g. 0x0123456) it exists a DELETE. If there isn't, you found what instance is leaking. Note the instance # (here instance #2 and #3)<br />
Run the test with the [[Documentation/4.0/Developers/Tutorials/Debug_Instructions|debugger]], set a breakpoint in the class constructor and ignore the break as many time as the instance number:<br />
(gdb) break vtkProperty2D::vtkProperty2D()<br />
Breakpoint 1 at 0x5b22d0e55d04296: file vtkProperty2D.cxx, line 22<br />
(gdb) ignore 1 2<br />
When the debugger stops, check the call stack:<br />
(gdb) backtrace<br />
By analyzing the trace, you should be able to find the faulty instance.<br />
</li><br />
<li> Analyze the code to see where the leak could be</li><br />
Here is a listing of the most common mistakes<br />
* this->MyXXX = vtkXXX::New();<br />
** Is there a matching this->MyXXX->Delete() ?<br />
** Are you sure <code>this->MyXXX</code> is <code>0</code> before being assigned a new pointer ? If not, then you need to add<br />
if (this->MyXXX != 0)<br />
{<br />
this->MyXXX->Delete();<br />
this->MyXXX = 0;<br />
}<br />
this->MyXXX = vtkXXX::New();<br />
</ol><br />
{{ombox<br />
|type=content<br />
|text=To reduce memory leaks, use the following tools:<br />
* <code>vtkNew<vtkXXX> myXXX;</code><br />
* <code>vtkSmartPointer<vtkXXX> myXXX = vtkSmartPointer<vtkXXX>::New()</code><br />
* <code>vtkSmartPointer<vtkXXX> myXXX; myXXX.TakeReference(this->CreateObjAndCallerOwnsReference())</code>.<br />
}}<br />
<br />
=Track a crash while accessing already deleted object pointer=<br />
If the application crashes by accessing an invalid pointer. The goal here is to find when (and why) the pointer is deleted before it is accessed .<br />
<ol><br />
<li>Before the crash, print the value of the pointer:</li><br />
Add before the crash (i.e. <code>this->MyObject->update()</code>)<br />
std::cout << ">>>>>Object pointer: " << this->MyObject << std::endl;<br />
<li>Add a counter in the destructor:</li><br />
Add in the object destructor (it can be in the base class (vtkObject or vtkMRMLNode) if you don't know the type):<br />
static int count = 0;<br />
std::cout << "#######Object Destructed: " << this << " " << count++ << std::endl;<br />
<li>Run the application and make it crash.</li><br />
<li>In the logs you shall see something like that:</li><br />
#######Object Destructed: 0x12345678 0<br />
#######Object Destructed: 0x12345679 1<br />
#######Object Destructed: 0x12345680 2<br />
>>>>>Object Pointer: 0x12345660<br />
>>>>>Object Pointer: 0x12345661<br />
>>>>>Object Pointer: 0x12345662<br />
#######Object Destructed: 0x12345660 3<br />
#######Object Destructed: 0x12345661 4<br />
#######Object Destructed: 0x12345662 5<br />
#######Object Destructed: 0x12345663 6<br />
>>>>>Object Pointer: 0x12345670<br />
>>>>>Object Pointer: 0x12345671<br />
>>>>>Object Pointer: 0x12345672<br />
#######Object Destructed: 0x12345660 7<br />
#######Object Destructed: 0x12345661 8<br />
#######Object Destructed: 0x12345662 9<br />
>>>>>Object Pointer: '''0x12345663'''<br />
Segfault<br />
<li> Search in the logs when the pointer before crash has been deleted. Set a conditional breakpoint in the debugger:</li><br />
(gdb) break MyObj.cxx:103 if count == 6<br />
or<br />
(gdb) break MyObj.cxx:103<br />
(gdb) ignore 1 5<br />
or if you don't want to use a debugger, you can make it crash the 6th time:<br />
assert(count != 6);<br />
<li> Analyze the backtrace to understand why the pointer has been deleted without letting know the object that tries to access it.</li><br />
</ol></div>JChris.FillionR