Login  Register

Re: [@dxli and @sand1024] please a tip for the RS_Eventhandler

Posted by dxli on Apr 12, 2025; 2:02am
URL: https://forum.librecad.org/fixed-thanks-please-a-tip-for-the-RS-Eventhandler-tp5726883p5726900.html

The crashing issue could hint an undefined behavior (buffer overflow, invalid pointer dereferenced, etc.)

Could you share a git branch with the issue? Of course, it helps to describe steps to reproduce.

The "finish()" issue is likely due to lifetime management as well.

Could you rebase to my latest changes to avoid raw pointers for actions?

emanuel wrote
I'm not really making any progress.

I have a class:

class LC_OverlaySlideAction:public RS_ActionInterface {
public:
    LC_OverlaySlideAction(
        const char *name,
        RS_EntityContainer &container,
        RS_GraphicView &graphicView,
        RS2::ActionType actionType = RS2::ActionNone);

    ~LC_OverlaySlideAction() override = default;

    void init(int status) override;
    void finish(bool updateTB = true) override;
    void trigger() override;
    void mouseMoveEvent(QMouseEvent* e) override;
    void mousePressEvent(QMouseEvent* e) override;
    void mouseReleaseEvent(QMouseEvent* e) override;

protected:
    void drawOverlaySlide(const QString &fileName);
private:
    bool middleButtonPressed{false};
};

but when I end the action with "ESC," RS_EventHandler::killAllActions() always calls RS_ActionInterface::finish(), never the overridden LC_OverlaySlideAction::finish().

Why doesn't this work? I have to reset values on finish.



Even weirder is, if I add just a virtual void bla() {} to the public: property of the RS_ActionInterface class, the entire LC crashes.
If I add it in different places, LC crashes in completely different places.
Once with QWidget attributes, or RS_Snapper.
Strange behavior.

class RS_ActionInterface : public RS_Snapper {
Q_OBJECT
public:
    RS_ActionInterface(const char* name,
                       RS_EntityContainer& container,
                       RS_GraphicView& graphicView,
                       RS2::ActionType actionType = RS2::ActionNone);
           ~RS_ActionInterface() override;

    virtual RS2::ActionType rtti() const;

    void setName(const char* _name);
    QString getName();

    virtual void init(int status);
   
    /* virtual void bla() {} <<<<<<< crashes QWidget attributes ??? */
   
    virtual void mouseMoveEvent(QMouseEvent*);
    virtual void mousePressEvent(QMouseEvent*);
    virtual void mouseReleaseEvent(QMouseEvent*);
    virtual void keyPressEvent(QKeyEvent* e);
    virtual void keyReleaseEvent(QKeyEvent* e);
    virtual void coordinateEvent(RS_CoordinateEvent*);
    virtual void commandEvent(RS_CommandEvent*);
    virtual QStringList getAvailableCommands();
    virtual void setStatus(int status);
    int getStatus() const;
    virtual void trigger();
    virtual bool isFinished() const;
    virtual void setFinished();
    virtual void finish(bool updateTB = true );
    virtual void setPredecessor(RS_ActionInterface* pre);
    void suspend() override;
    void resume() override;
    virtual void hideOptions();
    virtual void showOptions();
   
    /* virtual void bla() {} <<<<<<< crashes RS_Snapper ??? */
   
    ...