From: Song Li (lisong++at++vrac.iastate.edu)
Date: 11/12/2001 10:00:10
after replece the code , it can pass , now the code looks like:
g1 = pfdNewPipe(0.1,0.1,100,pfGetSharedArena());
g2 = pfdNewSphere( 100,pfGetSharedArena());
g = new pfGeode;
.......
but this function is a part of a large project, after doing this, the
program stucked elsewhere (when create pfScene), so I think the real
problem hasn't been solved..... any more suggestions ?
Marc Mendez wrote:
> >
> >
> > g = (pfGeode *)pfMalloc(sizeof(pfGeode),pfGetSharedArena());
> >
> > g1 = (pfGeoSet *)pfMalloc(sizeof(pfGeoSet),pfGetSharedArena());
> > g2 = (pfGeoSet *)pfMalloc(sizeof(pfGeoSet),pfGetSharedArena());
> >
> What you ve just made there is allocating memory of pfGeoSet size ...
>
> > g1 = pfdNewPipe(0.1,0.1,100,pfGetSharedArena());
> > g2 = pfdNewSphere( 100,pfGetSharedArena());
> >
> Those pfdNewXXXX functions allocate memory for you AND initialize your
> data structures (calling their constructors). This is the way you should
> create your objects.
>
> > //in a function
> > ......then set color, looks good......
> > g->addGSet(g1); //program crashes here
> > g->addGSet(g2);
> > .........
> > did I do something wrong ?????? Thanks!
> >
> Yes, you have to initialize your pfGeode object !
>
> Your code should look like :
>
> // constructor
> g = pfNewGeode();
> g1 = pfdNewPipe(0.1,0.1,100,pfGetSharedArena());
> g2 = pfdNewSphere( 100,pfGetSharedArena());
>
> And using your objects in the function should now work :
> - same thing ...
>
> You ll tell if it s working ???
>
> Marc.
> PS : remember that allocation and initialization won t come together
> automatically.
> You can t make any supposition on pInteger value down there :
>
> int* pInteger = (int*)malloc(sizeof(int));
>
> on different platforms (SGI, linux, SUN, IBM ...) you will certainly get
> different values except maybe in debug mode where every variable is set
> to its default value (0 usually).
-- Song Li VRAC(Virtual Reality Application Center),Iowa State University Email: lisong++at++vrac.iastate.edu Homepage: http://www.vrac.iastate.edu/~lisong
This archive was generated by hypermail 2b29 : Mon Nov 12 2001 - 09:59:26 PST