Hello,
I apologize since this is rather a n00bish question, but I can't figure this one out.
class View //simplified
{
public:
ROILine* ROI() {return _roi;} //setter does some control stuff...
private:
ROILine *_roi;
}
class ROI : public eq::Object
{
public:
//virtual ROI(ROI* copy) = 0;
virtual ~ROI() {};
virtual uint32_t getType() = 0;
virtual void reset() = 0;
virtual bool addPoint( eq::Vector3f point ) = 0;
virtual bool previewPoint( eq::Vector3f point ) = 0;
virtual bool getNotationLocation( eq::Vector3f& point ) = 0;
virtual bool draw() = 0;
protected:
enum ROIType {
NONE = 0,
LINE,
POLY,
AREA,
VOLUME
};
enum ROIMeasure {
RM_LENGTH = 1,
RM_AREA,
RM_VOLUME,
};
private:
};
class ROILine : virtual public ROI
{
public:
ROILine();
ROILine(ROILine* copy);
ROILine(const ROILine& copy);
virtual ~ROILine() {SFLog(@"Destroying ROILine: 0x%x",this);};
void reset();
float distance() { return _start.distance(_end); }
// ROI Interface
uint32_t getType() { return ROI::LINE; }
virtual bool draw();
bool addPoint( eq::Vector3f point );
bool previewPoint( eq::Vector3f point );
bool getNotationLocation( eq::Vector3f& point );
eq::net::DataOStream& serialize(eq::net::DataOStream& os) ;
eq::net::DataIStream& deserialize(eq::net::DataIStream& is) ;
protected:
enum ROILineState { // RLS_
RLS_RESET,
RLS_START,
RLS_PREVIEW,
RLS_END,
};
private:
uint32_t _state;
eq::Vector3f _start;
eq::Vector3f _end;
};
ROILine::ROILine(const ROILine& copy) : ROI()
{
reset();
switch (copy._state)
{
case RLS_PREVIEW:
case RLS_END:
addPoint(eq::Vector3f(copy._start));
addPoint(eq::Vector3f(copy._end));
break;
case RLS_START:
addPoint(eq::Vector3f(copy._start));
break;
case RLS_RESET:
default:
break;
}
}
/*!
@abstract resets the line values and state
*/
void ROILine::reset()
{
_state = RLS_RESET;
_end = eq::Vector3f::ZERO;
_start = eq::Vector3f::ZERO;
}
/*!
@abstract if it has 2 points, draw the line. (_state > _PREVIEW)
@discussion assumes GL is already set up. Executes drawing commands.
@result true if the line was drawn
*/
bool ROILine::draw()
{
bool retVal = false;
if (_state >= RLS_PREVIEW) {
//glTranslatef(0.0f, 0.0f, -1.0f); //Back Up?
glColor3f( 1.0f, 0.0f, 0.0f ); //Red
glEnable( GL_LINE_SMOOTH );
glLineWidth( 1 );
glBegin( GL_LINES );
{
glVertex3fv( _start.array );
glVertex3fv( _end.array );
}
glEnd();
//glTranslatef(0.0f, 0.0f, 1.0f); // Return
retVal = true;
}
return retVal;
}
// Elsewhere...
View *v = getView(); // returns the view object
// Destroys each time, but works wonderfully
ROILine r = ROILine(*(v->ROI()));
r.draw();
// Does not work (EXC_BAD_ACCESS)
v->ROI()->draw();
// Does not work (EXC_BAD_ACCESS on draw());
ROILine *r = v->ROI();
r->draw(); // debug shows r != 0x0
The Errors I get are as follows when I break on r->draw()
and continue.
[Switching to process 12453]
Current language: auto; currently objective-c++
Warning: the current language does not match this frame.
(gdb) continue
Program received signal: “EXC_BAD_ACCESS”.
The "EXC_BAD_ACCESS"
occurs on r->draw()
or v->ROI()->draw()
It doesn't step into the program at all, just halts and bt
gives me a ??
My copy constructor works, because the draw() function actually draws where it's supposed to (instead of !!@#$!4!#@ land) What I don't udnerstand, is why copying the value works, but accessing v->ROI()->draw()
does not. it MUST have v->ROI()
in order to make the copy!!
yes? ... no?
so confused...
Thanks,