Installing mouse causes segment fault in Dosbox

  allegro4, c++, dosbox

I’m making a simple program that supports GUI on DOS using Allegro4.
To implement mouse operation, I’ve created a shape object which presents current information of mouse.
Allegro provides lots of useful global variables such as mouse_x, mouse_y, mouse_b, etc. And these can be used only after the mouse driver is installed by the following code.

install_mouse();

This is my MousePointerObjectClass.

class MousePointerObject : public GameObject {
public:
    MousePointerObject(Scene *scene, std::shared_ptr<GameObject> parent = nullptr, std::string res = "");
    virtual void preupdate();
    virtual void collides(GameObject &other);
    void notCollides(GameObject &other);

private:
    int pressed_;
    int released_;

    friend class Scene;
};
MousePointerObject::MousePointerObject(Scene *scene, std::shared_ptr<GameObject> parent, std::string res)
    : GameObject (scene, parent)
{
    setRenderer(new MousePointerRenderer(res + "/renderer"));
    setCollider(new PointCollider({0, 0}));
}

void MousePointerObject::preupdate()
{
    place(Vector<float>(mouse_x, mouse_y));

    static int held_buttons = 0;
    int changed = mouse_b ^ held_buttons;
    pressed_ = changed & mouse_b;
    released_ = changed & ~mouse_b;
    held_buttons = mouse_b;
}

void MousePointerObject::collides(GameObject &other)
{
    if (pressed_ > 0)
        other.mouseDown(pressed_);
    if (released_ > 0)
        other.mouseUp(released_, true);
    other.mouse_inside_ = true;
}

void MousePointerObject::notCollides(GameObject &other)
{
    other.mouse_inside_ = false;
    if (released_ > 0)
        other.mouseUp(released_, false);
}

I cross-compiled this program on Ubuntu using DJGPP, and it works very well on Ubuntu and Real Dos without any conflicts.
But when it is going to be run on Dosbox or Dosbox-x, it causes segment fault.
Whether or not the mouse pointer is displayed on the screen, once install_mouse() is called, Dosbox exits unexpectedly when I move the mouse pointer.
I struggled so much to fix this issue, but they don’t work at all.

Any suggestion will be very appreciated.

Source: Windows Questions C++

LEAVE A COMMENT