[vtkusers] App crashes unless compiled with debug config (Windows)

Bill Lorensen bill.lorensen at gmail.com
Sat Sep 3 13:22:44 EDT 2016


Since you don't show targetArray
Try
for (int i = 0; i < sourceFiles->GetNumberOfValues(); i++)


On Sat, Sep 3, 2016 at 1:49 AM, Oliver Cairncross
<op.cairncross at gmail.com> wrote:
> (Oh sorry I'll copy it down)
>
> What I'm doing is pretty straight forward. I haven't changed the vtk code at
> all.
>
> vtkDirectory * sourceDir = vtkDirectory::New();
> sourceDir->Open(sourceString.c_str());
> vtkSortFileNames * sourceFiles = vtkSortFileNames::New();
> sourceFiles->SkipDirectoriesOn();
> sourceFiles->NumericSortOff();
> sourceFiles->SetInputFileNames(sourceDir->GetFiles());
> sourceFiles->Update();
>
> for (int i = 0; i < targetArray->GetNumberOfValues(); i++)
> {
>      string s1 = sourceFiles->GetFileNames()->GetValue(i); // crash!
> }
>
> Thanks
> Ollie
>
> On 3 September 2016 at 00:02, David E DeMarle <dave.demarle at kitware.com>
> wrote:
>>
>> You forgot to reply all to keep the discussion on the mailing list for
>> posterity.
>>
>> David E DeMarle
>> Kitware, Inc.
>> R&D Engineer
>> 21 Corporate Drive
>> Clifton Park, NY 12065-8662
>> Phone: 518-881-4909
>>
>> On Fri, Sep 2, 2016 at 2:17 AM, Oliver Cairncross
>> <op.cairncross at gmail.com> wrote:
>>>
>>> What I'm doing is pretty straight forward. I haven't changed the vtk code
>>> at all.
>>>
>>> vtkDirectory * sourceDir = vtkDirectory::New();
>>> sourceDir->Open(sourceString.c_str());
>>> vtkSortFileNames * sourceFiles = vtkSortFileNames::New();
>>> sourceFiles->SkipDirectoriesOn();
>>> sourceFiles->NumericSortOff();
>>> sourceFiles->SetInputFileNames(sourceDir->GetFiles());
>>> sourceFiles->Update();
>>>
>>> for (int i = 0; i < targetArray->GetNumberOfValues(); i++)
>>> {
>>>      string s1 = sourceFiles->GetFileNames()->GetValue(i); // crash!
>>> }
>>>
>>> Thanks
>>> Ollie
>>>
>>> On 2 September 2016 at 13:45, David E DeMarle <dave.demarle at kitware.com>
>>> wrote:
>>>>
>>>> Whatever your sourceFiles->GetFileNames object has uninitialized
>>>> pointers.
>>>>
>>>> Debug mode initializes all values to 0, release does not (in order to
>>>> save run time), but this leaves you with some pointer pointing to nonsense.
>>>>
>>>>
>>>>
>>>> David E DeMarle
>>>> Kitware, Inc.
>>>> R&D Engineer
>>>> 21 Corporate Drive
>>>> Clifton Park, NY 12065-8662
>>>> Phone: 518-881-4909
>>>>
>>>> On Thu, Sep 1, 2016 at 11:32 PM, Oliver Cairncross
>>>> <op.cairncross at gmail.com> wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>> vtk 7, msvc 14, windows 10
>>>>>
>>>>> I've had this problem before and thought it was something bad in my
>>>>> tool chain. But I've rebuild everything from scratch and it's still a
>>>>> problem.
>>>>>
>>>>> If I do something simple like
>>>>>
>>>>> string s1 = sourceFiles->GetFileNames()->GetValue(i);
>>>>>
>>>>> it runs fine in debug mode. When I compile in RelwithDebInfo it crashes
>>>>> with a bad allocation.
>>>>> When I have a look at the object the there is garbage where the string
>>>>> is supposed to be. As if it hasn't been initialised. I am calling an
>>>>> sourceFiles->Update() beforehand.
>>>>>
>>>>> Interestingly if I do
>>>>>
>>>>> cout << sourceFiles->GetFileNames()->GetValue(i);
>>>>> string s1 = sourceFiles->GetFileNames()->GetValue(i);
>>>>>
>>>>> it will print to console and then crash on the next line.
>>>>>
>>>>> Is anyone else having this problem?
>>>>>
>>>>> Cheers
>>>>> ollie
>>>>>
>>>>> _______________________________________________
>>>>> Powered by www.kitware.com
>>>>>
>>>>> Visit other Kitware open-source projects at
>>>>> http://www.kitware.com/opensource/opensource.html
>>>>>
>>>>> Please keep messages on-topic and check the VTK FAQ at:
>>>>> http://www.vtk.org/Wiki/VTK_FAQ
>>>>>
>>>>> Search the list archives at: http://markmail.org/search/?q=vtkusers
>>>>>
>>>>> Follow this link to subscribe/unsubscribe:
>>>>> http://public.kitware.com/mailman/listinfo/vtkusers
>>>>>
>>>>
>>>
>>
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>



-- 
Unpaid intern in BillsBasement at noware dot com


More information about the vtkusers mailing list