Working on the registerPressedKey for freecad polyline

Ok… So I thought I had the  registerPressedKey function working, but for some reason I’m generating a segmentation fault which I don’t understand at the moment ;(

So… I need to retrace my steps to see where things when south.

class SketcherGuiExport DrawSketchHandler
{
public:
DrawSketchHandler();
virtual ~DrawSketchHandler();

virtual void activated(ViewProviderSketch *sketchgui){};
virtual void mouseMove(Base::Vector2D onSketchPos)=0;
virtual bool pressButton(Base::Vector2D onSketchPos)=0;
virtual bool releaseButton(Base::Vector2D onSketchPos)=0;
virtual bool onSelectionChanged(const Gui::SelectionChanges& msg) { return false; };

virtual void quit(void);

friend class ViewProviderSketch;

// get the actual highest vertex index, the next use will be +1
int getHighestVertexIndex(void);
// get the actual highest edge index, the next use will be +1
int getHighestCurveIndex(void);

int seekAutoConstraint(std::vector<AutoConstraint> &suggestedConstraints,
const Base::Vector2D &Pos, const Base::Vector2D &Dir, Type selType = VERTEX);
void createAutoConstraints(const std::vector<AutoConstraint> &autoConstrs,
int geoId, Sketcher::PointPos pointPos=Sketcher::none);

void setPositionText(const Base::Vector2D &Pos);
void resetPositionText(void);
void renderSuggestConstraintsCursor(std::vector<AutoConstraint> &suggestedConstraints);

    void registerPressedKey(bool pressed, SoKeyboardEvent::Key key);
    bool keyArcPressed(void);
 private:
    SoKeyboardEvent::Key keyArcValue;
    SoKeyboardEvent::Key mode;

protected:
// helpers
void setCursor( const QPixmap &p,int x,int y );
void unsetCursor(void);
void applyCursor(void);
void applyCursor(QCursor &newCursor);

ViewProviderSketch *sketchgui;
QCursor oldCursor;
QCursor actCursor;
};

} // namespace SketcherGui

I created keyArcValue value because, I wanted to leave the option to make it user configurable in the future…  I initialize it in the constructor.

—-

DrawSketchHandler::DrawSketchHandler()
: sketchgui(0)
{

//at some point may want to make keyArcValue user configurable
keyArcValue=SoKeyboardEvent::A;
mode=SoKeyboardEvent::ANY;

}

void DrawSketchHandler::registerPressedKey(bool pressed, SoKeyboardEvent::Key key)
{
if (pressed)
mode = key;
else
mode = SoKeyboardEvent::ANY;
}
bool DrawSketchHandler::keyArcPressed(void)
{
if (mode == keyArcValue)
return true;
else
return false;
}

—–
I’m having registerPressedKey called from here:

bool ViewProviderSketch::keyPressed(bool pressed, int key)
{
switch (key)
{
case SoKeyboardEvent::ESCAPE:
{
// make the handler quit but not the edit mode
if (edit && edit->sketchHandler) {
if (!pressed)
edit->sketchHandler->quit();
return true;
}
return false;
}
default:
{
edit->sketchHandler->registerPressedKey(pressed,(SoKeyboardEvent::Key)key);
}

}

return true; // handle all other key events
}

—-

Ok… So I’m in sketch mode (in debug) and I just press and depress the A key and I get this message

The inferior stopped because it received a signal from the Operating System.

Signal name :

SIGSEGV

Signal meaning :

Segmentation fault

And it debugger is on this line:

void DrawSketchHandler::registerPressedKey(bool pressed, SoKeyboardEvent::Key key)
{
if (pressed)
     mode = key;
else
mode = SoKeyboardEvent::ANY;
}
bool DrawSketchHandler::keyArcPressed(void)
{
if (mode == keyArcValue)
return true;
else
return false;
}

And the call stack looks like this:
0    SketcherGui::DrawSketchHandler::registerPressedKey    DrawSketchHandler.cpp    405    0x7fffd272880d
1    SketcherGui::ViewProviderSketch::keyPressed    ViewProviderSketch.cpp    286    0x7fffd2703a42
2    Gui::ViewProvider::eventCallback    ViewProvider.cpp    182    0x7ffff779a121
3    SoEventCallback::handleEvent(SoHandleEventAction*)    /usr/lib/libCoin.so.60    0    0x7ffff51c3e0b
4    SoNode::handleEventS(SoAction*, SoNode*)    /usr/lib/libCoin.so.60    0    0x7ffff51dcda7
5    SoAction::traverse(SoNode*)    /usr/lib/libCoin.so.60    0    0x7ffff4fa44f7
6    SoChildList::traverse(SoAction*, int, int)    /usr/lib/libCoin.so.60    0    0x7ffff50f8ded
7    SoGroup::doAction(SoAction*)    /usr/lib/libCoin.so.60    0    0x7ffff51cffbb
8    SoSeparator::doAction(SoAction*)    /usr/lib/libCoin.so.60    0    0x7ffff51f393f
9    Gui::SoFCUnifiedSelection::handleEvent    SoFCUnifiedSelection.cpp    322    0x7ffff76f1ef9
10    SoNode::handleEventS(SoAction*, SoNode*)    /usr/lib/libCoin.so.60    0    0x7ffff51dcda7
11    SoAction::traverse(SoNode*)    /usr/lib/libCoin.so.60    0    0x7ffff4fa44f7
12    SoChildList::traverse(SoAction*, int, int)    /usr/lib/libCoin.so.60    0    0x7ffff50f8ded
13    SoGroup::doAction(SoAction*)    /usr/lib/libCoin.so.60    0    0x7ffff51cffbb
14    SoSeparator::doAction(SoAction*)    /usr/lib/libCoin.so.60    0    0x7ffff51f393f
15    SoNode::handleEventS(SoAction*, SoNode*)    /usr/lib/libCoin.so.60    0    0x7ffff51dcda7
16    SoAction::traverse(SoNode*)    /usr/lib/libCoin.so.60    0    0x7ffff4fa44f7
17    SoChildList::traverse(SoAction*, int, int)    /usr/lib/libCoin.so.60    0    0x7ffff50f8ded
18    SoGroup::doAction(SoAction*)    /usr/lib/libCoin.so.60    0    0x7ffff51cffbb
19    SoSeparator::doAction(SoAction*)    /usr/lib/libCoin.so.60    0    0x7ffff51f393f
20    SoNode::handleEventS(SoAction*, SoNode*)    /usr/lib/libCoin.so.60    0    0x7ffff51dcda7
…    <More>
Hmm.. I missing something obvious here:
Oh hold on….
Ah I think I know whats going on here:
DrawSketchHandler is inherited into DrawSketchhandlerline set and a bunch of other objects… If the keypress is depressed and none of these things are in memory…. Walla  seg fault…

 

 

 

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *