<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:arial,helvetica,sans-serif;font-size:10pt"><div><br></div><div style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"><br><div style="font-family: tahoma,new york,times,serif; font-size: 10pt;"><font face="Tahoma" size="2"><hr size="1"><b><span style="font-weight: bold;">From:</span></b> "insight-users-request@itk.org" &lt;insight-users-request@itk.org&gt;<br><b><span style="font-weight: bold;">To:</span></b> insight-users@itk.org<br><b><span style="font-weight: bold;">Sent:</span></b> Thu, May 6, 2010 4:50:57 AM<br><b><span style="font-weight: bold;">Subject:</span></b> Insight-users Digest, Vol 73, Issue 19<br></font><br>Send Insight-users mailing list submissions to<br>&nbsp;&nbsp;&nbsp; <a ymailto="mailto:insight-users@itk.org" href="mailto:insight-users@itk.org">insight-users@itk.org</a><br><br>To subscribe or unsubscribe via the
 World Wide Web, visit<br>&nbsp;&nbsp;&nbsp; <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>or, via email, send a message with subject or body 'help' to<br>&nbsp;&nbsp;&nbsp; <a ymailto="mailto:insight-users-request@itk.org" href="mailto:insight-users-request@itk.org">insight-users-request@itk.org</a><br><br>You can reach the person managing the list at<br>&nbsp;&nbsp;&nbsp; <a ymailto="mailto:insight-users-owner@itk.org" href="mailto:insight-users-owner@itk.org">insight-users-owner@itk.org</a><br><br>When replying, please edit your Subject line so it is more specific<br>than "Re: Contents of Insight-users digest..."<br><br><br>Today's Topics:<br><br>&nbsp;  1. Re: Using ImportFilter and PasteImageFilter (Quent)<br>&nbsp;  2. Re: Wrapping ITK in OSX 10.6 (Lassi Paavolainen)<br><br><br>----------------------------------------------------------------------<br><br>Message:
 1<br>Date: Thu, 6 May 2010 00:30:13 -0700 (PDT)<br>From: Quent &lt;<a ymailto="mailto:quentin.bezsilko@gmail.com" href="mailto:quentin.bezsilko@gmail.com">quentin.bezsilko@gmail.com</a>&gt;<br>Subject: Re: [Insight-users] Using ImportFilter and PasteImageFilter<br>To: <a ymailto="mailto:insight-users@itk.org" href="mailto:insight-users@itk.org">insight-users@itk.org</a><br>Message-ID: &lt;<a ymailto="mailto:28470202.post@talk.nabble.com" href="mailto:28470202.post@talk.nabble.com">28470202.post@talk.nabble.com</a>&gt;<br>Content-Type: text/plain; charset=UTF-8<br><br>In the following lines:<br>-------------------------<br>&nbsp;&nbsp; unsigned long i, x;<br>&nbsp;&nbsp;&nbsp; float * fImage;<br>&nbsp;&nbsp;&nbsp; pixList = 
[new2DViewer pixList];<br>&nbsp;&nbsp;&nbsp; for(i=0;i&lt;[pixList count]; i++){<br>&nbsp;&nbsp;&nbsp;
 &nbsp;&nbsp;&nbsp; curPix = [pixList objectAtIndex:i];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; x = height * width;<br>&nbsp;&nbsp;&nbsp;
 &nbsp;&nbsp;&nbsp; fImage = [curPix fImage];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; while(x&gt;0){<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
*localBuffer = *fImage;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; localBuffer++;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
cptLocalBuffer++;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fImage++;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; x--;<br>&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>-----------------------<br><br>you are incrementing the pointer to your allocated buffer (localBuffer++). So, when you use it later in:<br><br>-----------------------<br> importFilter-&gt;SetImportPointer(localBuffer, numberOfPixels, true);<br>-----------------------<br><br>It is no longer pointing to the memory space you allocated but just beyond that leading to your unexpected crash. You should rewrite you pixel copy code to something like:<br><br>
-------------------------<br>
&nbsp;&nbsp; unsigned long i, x;<br>

&nbsp;&nbsp; x = height * width;<br>
&nbsp;&nbsp;&nbsp; float * fImage;<br>
&nbsp;&nbsp;&nbsp; float* tmpLocalBufferPtr;<br>&nbsp; &nbsp;&nbsp;tmpLocalBufferPtr = localBuffer;<br>
&nbsp;&nbsp;&nbsp; pixList = 
[new2DViewer pixList];<br>
&nbsp;&nbsp;&nbsp; for(i=0;i&lt;[pixList count]; i++){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; memcpy( tmpLocalBufferPtr, [curPix fImage], x);<br>
&nbsp;&nbsp;&nbsp;
 &nbsp;&nbsp;&nbsp; tmpLocalBufferPtr += x;<br>
&nbsp;&nbsp;&nbsp; }<br>-----------------------<br><br>Todd Jensen<br></div></div>
</div></body></html>