开发者

Mysterious SIGABRT in destructor if certain member variables are initialized in the constructor

开发者 https://www.devze.com 2023-03-04 12:40 出处:网络
I have the following Qt class: class GLWidget : public QGLWidget { Q_OBJECT public: GLWidget(QWidget *parent = 0);

I have the following Qt class:

class GLWidget : public QGLWidget
{
    Q_OBJECT
public:
    GLWidget(QWidget *parent = 0);
private:
    void initializeGL();
    void resizeGL(int w, int h);
    void paintGL();

    double posX;
    double posY;
    double posZ;
};

When I put 开发者_如何学Pythonthis in the constructor, my program produces a SIGABRT during GLWidget::~GLWidget:

this->posX = 0.0;
this->posY = 0.0;
this->posZ = 1.0;

These member variables aren't used anywhere else in the class. If I don't initialize the member variables, the program doesn't fail. How can this lead to a SIGABRT?

Stack trace

Mysterious SIGABRT in destructor if certain member variables are initialized in the constructor


Did you check the core file to see where it died?

That said, the most likely scenario is division by zero and/or assertion that X and Y are not zero.

EDIT: Also it seems likely that when you don't initialize the values the program is behaving wrong but it just appears to work correctly/better.

EDIT2 in response to comment: You can configure unix/linux systems (with coreadm) to leave a "core" file behind when you program crashes or aborts. It contains information about the call stack, registers, memory, etc. It does appear that you found it (or something similar). The line that says

free(): invalid next size (fast): 0x00000000006e3110 *

actually makes me change my mind. It looks like your heap is corrupted, and the deletion is causing that to become visible. One possibility is that you deleted the object twice. If you're on Linux, valgrind will probably be your best way to figure out what happened.


Adding these variables moved code around. There's a bug somewhere that didn't cause a visible problem until the rearrangement occurred. I would run it in a debugger or add logging to it to determine where the problem is. Use the "Divide and conquer" method to minimize the time finding the bug.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号