[ITK-users] [ITK] itk::CastImageFilter causes AccessViolationException

Andrew Harris aharr8 at uwo.ca
Thu Jul 28 12:59:13 EDT 2016


Thanks all for the help, I wrote a for loop to do the same task and got the
same error, and upon investigating it turns out the program I am building
upon was passing the incorrect dimensions for the image buffer. Turns out
this is a PEBKAC error.

--

AH


-----------------------------------------------------------------------------------------------

*This email and any attachments thereto may contain private,
confidential, and privileged materials for the sole use of the intended
recipient. Any reviewing, copying, or distribution of this email (or any
attachments thereto) by other than the intended recipient is strictly
prohibited. If you are not the intended recipient, please contact the
sender immediately and permanently destroy this email and any attachments
thereto.*

On Thu, Jul 28, 2016 at 11:13 AM, Dženan Zukić <dzenanz at gmail.com> wrote:

> I would focus on the input array now. The cast filter is perhaps accessing
> elements past the end of the input array. Try passing a smaller number for
> Z size and see whether that solves the crash (access violation).
>
> On Thu, Jul 28, 2016 at 10:24 AM, Andrew Harris <aharr8 at uwo.ca> wrote:
>
>> Thanks all for getting back to me.  I put in a call to update the
>> importFilter and upon debugging found that the image variable is getting
>> the correct size settings and number of elements (or at least it is the
>> same as the importFilter finds).  I tried casting the imageSize to unsigned
>> int and got the same numbers throughout, and still had the exception at
>> castImage->Update().  Here is the stack trace at the exception:
>>
>> > BING_Andrew.exe!std::_Transform<unsigned char const *,float
>> *,itk::ImageAlgorithm::StaticCast<unsigned char,float> >(unsigned char*
>> _First, unsigned char* _Last, float* _Dest,
>> itk::ImageAlgorithm::StaticCast<unsigned char,float> _Func) Line 950 + 0x9
>> bytes C++
>>   BING_Andrew.exe!std::_Transform1<unsigned char const *,float
>> *,itk::ImageAlgorithm::StaticCast<unsigned char,float> >(unsigned char*
>> _First, unsigned char* _Last, float* _Dest,
>> itk::ImageAlgorithm::StaticCast<unsigned char,float> _Func,
>> std::random_access_iterator_tag __unnamed004,
>> std::random_access_iterator_tag __unnamed005) Line 988 + 0x2b bytes C++
>>   BING_Andrew.exe!std::_Transform1<unsigned char const *,float
>> *,itk::ImageAlgorithm::StaticCast<unsigned char,float> >(unsigned char*
>> _First, unsigned char* _Last, float* _Dest,
>> itk::ImageAlgorithm::StaticCast<unsigned char,float> _Func,
>> std::integral_constant<bool,0> __unnamed004) Line 1012 + 0x6d bytes C++
>>   BING_Andrew.exe!std::transform<unsigned char const *,float
>> *,itk::ImageAlgorithm::StaticCast<unsigned char,float> >(unsigned char*
>> _First, unsigned char* _Last, float* _Dest,
>> itk::ImageAlgorithm::StaticCast<unsigned char,float> _Func) Line 1026 +
>> 0x48 bytes C++
>>   BING_Andrew.exe!itk::ImageAlgorithm::CopyHelper<unsigned
>> char,float>(unsigned char* first, unsigned char* last, float* result) Line
>> 213 + 0x14 bytes C++
>>   BING_Andrew.exe!itk::ImageAlgorithm::DispatchedCopy<itk::Image<unsigned
>> char,3>,itk::Image<float,3> >(itk::Image<unsigned char,3>* inImage,
>> itk::Image<float,3>* outImage, itk::ImageRegion<3>& inRegion,
>> itk::ImageRegion<3>& outRegion, std::integral_constant<bool,1>
>> __unnamed004) Line 136 + 0x12 bytes C++
>>   BING_Andrew.exe!itk::ImageAlgorithm::Copy<unsigned
>> char,float,3>(itk::Image<unsigned char,3>* inImage, itk::Image<float,3>*
>> outImage, itk::ImageRegion<3>& inRegion, itk::ImageRegion<3>& outRegion)
>> Line 113 C++
>>   BING_Andrew.exe!itk::CastImageFilter<itk::Image<unsigned
>> char,3>,itk::Image<float,3> >::ThreadedGenerateData(itk::ImageRegion<3>&
>> outputRegionForThread, unsigned int threadId) Line 73 + 0x13 bytes C++
>>   [External Code]
>>   BING_Andrew.exe!itk::ImageSource<itk::Image<float,3>
>> >::ThreaderCallback(void* arg) Line 316 C++
>>   BING_Andrew.exe!itk::MultiThreader::SingleMethodProxy(void * arg)
>>  Line 437 + 0xe bytes C++
>>   msvcr120d.dll!03573651()
>>   [Frames below may be incorrect and/or missing, no symbols loaded for
>> msvcr120d.dll]
>>   msvcr120d.dll!03573861()
>>   kernel32.dll!74c738f4()
>>   ntdll.dll!776d5de3()
>>   ntdll.dll!776d5dae()
>>
>> I'm attaching this as a txt file also because the formatting looks a
>> little weird in my email client, it might be easier to read as plain text.
>> One other thing I forgot to mention, the window generated by the exception
>> has the following text as well:
>> Additional information: Attempted to read or write protected memory. This
>> is often an indication that other memory is corrupt.
>>
>> Thanks again for the help.
>>
>> --
>>
>> AH
>>
>>
>>
>> -----------------------------------------------------------------------------------------------
>>
>> *This email and any attachments thereto may contain private,
>> confidential, and privileged materials for the sole use of the intended
>> recipient. Any reviewing, copying, or distribution of this email (or any
>> attachments thereto) by other than the intended recipient is strictly
>> prohibited. If you are not the intended recipient, please contact the
>> sender immediately and permanently destroy this email and any attachments
>> thereto.*
>>
>> On Thu, Jul 28, 2016 at 9:01 AM, Bradley Lowekamp <brad at lowekamp.net>
>> wrote:
>>
>>> Hello,
>>>
>>> I noticed you are using type int for you imageSiize. How big is your
>>> image? You may be overflowing when computing the number of pixels.
>>>
>>> I don’t think you have provided a stack trace of when the error occurs.
>>> That would be helpful too.
>>>
>>> Brad
>>>
>>> On Jul 28, 2016, at 8:29 AM, Dženan Zukić <dzenanz at gmail.com> wrote:
>>>
>>> Have you tried calling Update on the import filter? That might be the
>>> problem. Cast filter is simple and non-special, I doubt it is the problem.
>>>
>>> On Wed, Jul 27, 2016 at 8:26 PM, Andrew Harris <aharr8 at uwo.ca> wrote:
>>>
>>>> Thanks Dženan, as I said in my previous email running Update() on the
>>>> castFilter pointer returns the same error.  I did put in a try/catch block
>>>> to update it though.
>>>>
>>>> --
>>>>
>>>> AH
>>>>
>>>>
>>>>
>>>> -----------------------------------------------------------------------------------------------
>>>>
>>>> *This email and any attachments thereto may contain private,
>>>> confidential, and privileged materials for the sole use of the intended
>>>> recipient. Any reviewing, copying, or distribution of this email (or any
>>>> attachments thereto) by other than the intended recipient is strictly
>>>> prohibited. If you are not the intended recipient, please contact the
>>>> sender immediately and permanently destroy this email and any attachments
>>>> thereto.*
>>>>
>>>> On Wed, Jul 27, 2016 at 5:16 PM, Dženan Zukić <dzenanz at gmail.com>
>>>> wrote:
>>>>
>>>>> Hi Andrew,
>>>>>
>>>>> I think that line 62 of .cpp should be:
>>>>> castFilter->Update();
>>>>> I don't see the pipeline updated elsewhere.
>>>>>
>>>>> Regards,
>>>>> Dženan
>>>>>
>>>>> On Wed, Jul 27, 2016 at 3:54 PM, Andrew Harris <aharr8 at uwo.ca> wrote:
>>>>>
>>>>>> Thanks for getting back to me, after conferring with a colleague I
>>>>>> tried using the output of the cast filter directly in the subsequent
>>>>>> pipeline rather than writing it to a new image object of the filter's
>>>>>> output type. I got the same error doing that, and also got the same error
>>>>>> just running Update() on the cast filter, which leads me to believe I'm
>>>>>> doing something wrong in setting up the cast filter.  I'm attaching my code
>>>>>> for the class I'm writing, hope it's something simple I'm doing wrong.
>>>>>> Currently it's throwing the exception at line 85 when the registration
>>>>>> transform initializer is activated.
>>>>>>
>>>>>> --
>>>>>>
>>>>>> AH
>>>>>>
>>>>>>
>>>>>>
>>>>>> -----------------------------------------------------------------------------------------------
>>>>>>
>>>>>> *This email and any attachments thereto may contain private,
>>>>>> confidential, and privileged materials for the sole use of the intended
>>>>>> recipient. Any reviewing, copying, or distribution of this email (or any
>>>>>> attachments thereto) by other than the intended recipient is strictly
>>>>>> prohibited. If you are not the intended recipient, please contact the
>>>>>> sender immediately and permanently destroy this email and any attachments
>>>>>> thereto.*
>>>>>>
>>>>>> On Tue, Jul 26, 2016 at 7:09 PM, Bradley Lowekamp <brad at lowekamp.net>
>>>>>> wrote:
>>>>>>
>>>>>>> Hello,
>>>>>>>
>>>>>>> The most common mistake here would be forgetting to call Allocate on
>>>>>>> your image. Beyond that sharing your code would be helpful.
>>>>>>>
>>>>>>> Brad
>>>>>>>
>>>>>>> On Jul 26, 2016, at 1:43 PM, Andrew Harris <aharr8 at uwo.ca> wrote:
>>>>>>>
>>>>>>> Hello,
>>>>>>> I am attempting to use the CastImageFilter to convert between
>>>>>>> unsigned char and float image types, and am getting a
>>>>>>> System.AccessViolationException at runtime.  I have seen reference to this
>>>>>>> being caused by referring to a pointer that is out of scope, but in this
>>>>>>> case both the image and the cast filter are delcared in the same method, so
>>>>>>> I’m not sure how it can be going out of scope.  I can include the header
>>>>>>> and definition files if that would be helpful.
>>>>>>>
>>>>>>> --
>>>>>>>
>>>>>>> AH
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> -----------------------------------------------------------------------------------------------
>>>>>>>
>>>>>>> *This email and any attachments thereto may contain private,
>>>>>>> confidential, and privileged materials for the sole use of the intended
>>>>>>> recipient. Any reviewing, copying, or distribution of this email (or any
>>>>>>> attachments thereto) by other than the intended recipient is strictly
>>>>>>> prohibited. If you are not the intended recipient, please contact the
>>>>>>> sender immediately and permanently destroy this email and any attachments
>>>>>>> thereto.*
>>>>>>>
>>>>>>> _____________________________________
>>>>>>> Powered by www.kitware.com
>>>>>>>
>>>>>>> Visit other Kitware open-source projects at
>>>>>>> http://www.kitware.com/opensource/opensource.html
>>>>>>>
>>>>>>> Kitware offers ITK Training Courses, for more information visit:
>>>>>>> http://www.kitware.com/products/protraining.php
>>>>>>>
>>>>>>> Please keep messages on-topic and check the ITK FAQ at:
>>>>>>> http://www.itk.org/Wiki/ITK_FAQ
>>>>>>>
>>>>>>> Follow this link to subscribe/unsubscribe:
>>>>>>> http://public.kitware.com/mailman/listinfo/insight-users
>>>>>>>
>>>>>>>
>>>>>>
>>>>>> _____________________________________
>>>>>> Powered by www.kitware.com
>>>>>>
>>>>>> Visit other Kitware open-source projects at
>>>>>> http://www.kitware.com/opensource/opensource.html
>>>>>>
>>>>>> Kitware offers ITK Training Courses, for more information visit:
>>>>>> http://www.kitware.com/products/protraining.php
>>>>>>
>>>>>> Please keep messages on-topic and check the ITK FAQ at:
>>>>>> http://www.itk.org/Wiki/ITK_FAQ
>>>>>>
>>>>>> Follow this link to subscribe/unsubscribe:
>>>>>> http://public.kitware.com/mailman/listinfo/insight-users
>>>>>>
>>>>>>
>>>>>
>>>>
>>> _____________________________________
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Kitware offers ITK Training Courses, for more information visit:
>>> http://www.kitware.com/products/protraining.php
>>>
>>> Please keep messages on-topic and check the ITK FAQ at:
>>> http://www.itk.org/Wiki/ITK_FAQ
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://public.kitware.com/mailman/listinfo/insight-users
>>>
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/insight-users/attachments/20160728/357ecdf0/attachment.html>


More information about the Insight-users mailing list