[vtkusers] syntax question

tom fogal tfogal at apollo.sr.unh.edu
Tue Jun 8 16:19:06 EDT 2004


You should learn to use gdb or one of its frontends if you prefer.
It will more than pay off in the long run.

Search for a 'gdb tutorial'. You're Feeling Lucky.

Basically though, add '-g' to your gcc commandline, and then
'gdb your_binary' and then 'run' from the gdb prompt. That will
tell you which function is the problem. 'print' out variables,
and check to see if your dereferencing a NULL (0x0) pointer.

Like I mentioned though, I'm fairly sure from just that snippet
that only Stuff[0]->HelloWorld() will work. 'vtkBClass **Stuff'
gives you a pointer to the base address of an array, thus you
'own' the base address. But you do not own BaseAddress+sizeof(vtkBclass),
which Stuff[1] would reference. So dereferencing Stuff via
Stuff[1] "should" segfault. It's conceivable that
Stuff[1] is in a portion of memory you own, in which case you
would get unpredictable results, but its more plausible that
Stuff[1] would be in memory you don't own, which would produce
a seg fault.

-tom

 <BAY99-F13WuO9rsZ6ZY0001942c at hotmail.com>"A J" writes:
>Okay yes I'm on a Redhat 8 but Im not at all familiar with this environment 
>yet....
>
>I'm not using a debugger , i'm compiling with gcc,
>I think I had tried a debugger awhile ago but it didnt like the .cxx 
>extensions..?
>
>
>>I'm surprised it works at all... Stuff[1] through Stuff[19]
>>won't be memory you own, and yet it is assigned to.
>>
>>what does the debugger say it is crashing on?
>>
>>I'm guessing you are in a Windows environment. I'm not very
>>familiar with Windows but I know that UNIX libc implementations
>>almost always have an environment variable you can set to allow
>>you to debug malloc() calls (MALLOC_CHECK_ on linux,
>>MALLOC_OPTIONS on freebsd, etc.). Perhaps there is a similar
>>mechanism available on Windows?
>>You may wish to try setting it and see if its an allocation
>>issue...
>>
>>-tom
>>
>>  <BAY99-F64sQPwFpH2cX000036f3 at hotmail.com>"A J" writes:
>> >Okay I almost have it... but I get a 'segmentation fault' at the end:
>> >
>> >vtkBclass **Stuff;
>> >for (int i=0; i<20; i++)
>> >	Stuff[i] = vtkBclass::New();
>> >
>> >Stuff[0]->HelloWorld();
>> >
>> >.. and then it crashes after it finishes executing the HelloWorld
>> >function.....
>> >!!!!
>> >
>> >so close but no cigar..!!  :o(
>> >
>> >
>> >
>> >
>> >>Oh hrm, I seem to have totally glazed over that you were
>> >>trying to allocate an array... Sorry 'bout that.
>> >>
>> >>Interesting question. Perhaps
>> >>
>> >>vtkBclass **stuff = vtkBclass::New()*[number]
>> >>
>> >>would do what you wanted?
>> >>
>> >>Just a stab in the dark.. I'll be interested to hear the
>> >>solution.
>> >>
>> >>-tom
>> >>
>> >>  <BAY99-F53CTVuy16xso0000c978 at hotmail.com>"A J" writes:
>> >> >Yes thanks tom , I've already inherited these from vtkObject,
>> >> >but now this means that instead of doing
>> >> >
>> >> >Bclass *stuff = new Bclass[ number ]
>> >> >
>> >> >I now have to do something like
>> >> >
>> >> >vtkBclass **stuff = vtkBclass::New() [number]
>> >> >
>> >> >or...???
>> >> >
>> >> >I just want a pointer to an array of vtkBclass's, not just one which
>> >>would
>> >> >obviously just be
>> >> >vtkBclass *stuff = vtkBclass::New();
>> >> >
>> >> >
>> >> >
>> >> >
>> >> >>AJ, use Bclass' New() member function.
>> >> >>
>> >> >>You should derive Bclass (and Aclass, for that matter) from a
>> >> >>vtkObject and it will then automagically obtain the vtkObject::New()
>> >> >>member function.
>> >> >>
>> >> >>Also, you should make sure your vtk* objects have their constructors
>> >> >>and destructors declared as protected, and additionally that the
>> >> >>destructors are declared virtual.
>> >> >>
>> >> >>HTH,
>> >> >>
>> >> >>-tom
>> >> >>
>> >> >>  <BAY99-F504GCjNNsqlt0003748a at hotmail.com>"A J" writes:
>> >> >> >Hi,
>> >> >> >
>> >> >> >Say I have my own classes called Aclass and Bclass
>> >> >> >
>> >> >> >and say I have now wrapped these to VTK classes so they are now 
>>known
>> >>as
>> >> >> >vtkAclass and vtkBclass
>> >> >> >
>> >> >> >Originally, I had:
>> >> >> >
>> >> >> >class Aclass
>> >> >> >{
>> >> >> >
>> >> >> >public:
>> >> >> >Bclass *stuff = new Bclass[ number ]
>> >> >> >  ....
>> >> >> >}
>> >> >> >
>> >> >> >
>> >> >> >So now that Aclass has become vtkAclass and same for vtkBclass.. 
>>what
>> >>is
>> >> >>the
>> >> >> >syntax to do this with the New() operator that I now have to use..? 
>>  I
>> >> >>had
>> >> >> >tried a few things but nothign works so far.. it must be something
>> >>very
>> >> >> >basic..! =S
>> >> >> >
>> >> >> >Thanks!!
>> >> >> >
>> >> >> >_________________________________________________________________
>> >> >> >Watch the online reality show Mixed Messages with a friend and 
>>enter
>> >>to
>> >> >>win
>> >> >> >a trip to NY
>> >> >>
>> >> 
>> >http://www.msnmessenger-download.click-url.com/go/onm00200497ave/direct/01/
>> >> >> >
>> >> >> >_______________________________________________
>> >> >> >This is the private VTK discussion list.
>> >> >> >Please keep messages on-topic. Check the FAQ at:
>> >> >><http://public.kitware.com/cgi-bin/vtkfaq>
>> >> >> >Follow this link to subscribe/unsubscribe:
>> >> >> >http://www.vtk.org/mailman/listinfo/vtkusers
>> >> >
>> >> >_________________________________________________________________
>> >> >Is your PC infected? Get a FREE online computer virus scan from 
>>McAfee®
>> >> >Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
>> >> >
>> >> >_______________________________________________
>> >> >This is the private VTK discussion list.
>> >> >Please keep messages on-topic. Check the FAQ at:
>> >><http://public.kitware.com/cgi-bin/vtkfaq>
>> >> >Follow this link to subscribe/unsubscribe:
>> >> >http://www.vtk.org/mailman/listinfo/vtkusers
>> >
>> >_________________________________________________________________
>> >FREE pop-up blocking with the new MSN Toolbar – get it now!
>> >http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/
>
>_________________________________________________________________
>FREE pop-up blocking with the new MSN Toolbar – get it now! 
>http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/
>
>_______________________________________________
>This is the private VTK discussion list. 
>Please keep messages on-topic. Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
>Follow this link to subscribe/unsubscribe:
>http://www.vtk.org/mailman/listinfo/vtkusers



More information about the vtkusers mailing list