[vtkusers] Access violation when using vtkPolyDataReader

Sean McInerney seanm at nmr.mgh.harvard.edu
Thu Jul 28 17:01:32 EDT 2005


Hi,

I agree that the segfault probably results from your use of the assert()
macro ... your code looks correct otherwise ....

1. Removal of the assertion (when NDEBUG is defined) should *not* be a
semantic change ... which your code does by eliminating the call to calloc.

2. The result of a call to calloc() is not really an invariant (and
therefore not good to assert) since it may return NULL in the course of
normal program operation (e.g. out of memory).

3. Why not use C++'s operator new? It throws an exception and aborts by
default if an allocation fails.
   e.g.: readers = vtkPolyDataReader* [fp.size()];

3b. Go wild! (if you feel the need to)
    e.g. try
           {
           readers = vtkPolyDataReader* [fp.size()];
           }
         catch (std::bad_alloc)
           {
           vtkErrorMacro(<< "Agggggh!!!");
           }

-Sean

David Cole wrote:
> Is "readers" NULL (or garbage) when you enter the for loop?
> Is the assert being compiled out? (release build?)
> 
> Hassan Amin wrote:
> 
>> Dear friends,
>>    The following  line  readers[i]=vtkPolyDataReader::New() is giving
>> me run time error(access violation writing location ). Can any body
>> help me ?
>>
>> Yours,
>>
>> S. Hassan Amin
>>
>> int inputs=fp.size();
>>  
>> assert(readers=(vtkPolyDataReader**)calloc(inputs,sizeof(vtkPolyDataReader*)));
>>
>>    for (int i=0;i<fp.size();i++)
>>    {
>>        readers[i]=vtkPolyDataReader::New();  // Gives me run time error
>>    }



More information about the vtkusers mailing list