[vtk-developers] Re: GL2PS: a few questions.
Prabhu Ramachandran
prabhu at aero.iitm.ernet.in
Wed Jun 25 10:28:13 EDT 2003
Hi,
Answering my dumb self.
>>>>> "PR" == Prabhu Ramachandran <prabhu at aero.iitm.ernet.in> writes:
I had asked this question earlier:
PR> 1. While adding support for mixed raster/vector output I tried
PR> creating an array of vtkIntArrays and ran into lots of
PR> trouble. I had code that looked like this:
vtkIntArray **ia;
ia = new vtkIntArray* [n];
ia[0] = vtkIntArray::New();
PR> This was created/initialized inside one function and then
PR> the array used in another. The initialization worked fine
PR> but I kept getting segfaults when I used 'ia' like so:
PR> ia[0]->GetNumberOfTuples()
PR> in another function. I solved my problem by using a
PR> vtkIntArray with multiple components but am curious to
PR> know whats wrong with the above and why I got the
PR> behaviour I did.
I figured out what was wrong. Not suprisingly, I was a moron.
I guess I'm too used to pass by reference but what happened was that I
was initializing the pointer inside the function where I was
allocating memory for it and I did not return the initialized pointer
and set it inside the calling function. So the original function was
(still) pointing to junk and I got segfaults. Thanks to Goodwin for
some of his comments.
Anyway the reason I'm saying this on the list is to tell you folks
that there is nothing wrong with vtkIntArray. Its just me.
cheers,
prabhu
More information about the vtk-developers
mailing list