2

我正在研究制作物理动画的 Qt/OpenGL gui。我尝试使用mousePressEventmouseMoveEvent功能进行旋转。

为此,我尝试QPoint lasPos为鼠标位置添加数据成员。但我不知道为什么我在执行时收到以下错误:

*** glibc detected *** ./YourGalaxy: corrupted double-linked list: 0x0000000001682a00 ***
======= Backtrace: =========
/lib/libc.so.6(+0x71bd6)[0x7f665940ebd6]
...

这是 GLWidget.hpp :

#ifndef GLWIDGET_H
#define GLWIDGET_H

#include <QGLShaderProgram>
#include <QGLWidget>
#include <QPoint>
#include <QTimer>
#include "NBody.hpp"
#include "Timer.h"

 class GLWidget : public QGLWidget
 {
     Q_OBJECT

 public:

     GLWidget(QWidget *parent = NULL);

     ~GLWidget();

     NBody *Galaxy;
     float m_particleRadius;
     float m_pointScale;
     QPoint lastPos;
     GLubyte *textureImage;
     GLuint texture;
     Timer timer;
     GLuint m_program;
     QTimer *m_timer;
     int count;
     double n_fps;

     GLuint _compileProgram(const char *source);
     void LoadGLTextures();
     void createVBO(uint size);
     void draw();
     void printStats();
     void zoom_scale(double factor);

 protected :

     void initializeGL();
     void mousePressEvent(QMouseEvent *event);
     void mouseMoveEvent(QMouseEvent *event);

 private slots:

     void processCurrent();

 private:

     int w_width;
     int w_height;
     GLfloat g_nearPlane;
     GLfloat g_farPlane;
     char** stats;

 };

 #endif

和 GLWidget.cpp 中的构造函数:

GLWidget::GLWidget(QWidget *parent) : QGLWidget(parent) {

    char *my_argv[] = { "NBody", NULL };
    int   my_argc = 1;
    int status;
    m_particleRadius = 0.5f;
    m_pointScale = 100.0f;
    w_width = 600;
    w_height = 600;
    g_nearPlane = 0.1f;
    g_farPlane = 1000.0f;
    count = 0;
    n_fps = 0.0;

    stats = new char* [3] ;
    for( int i = 0 ; i < 3 ; i++ )
        stats[i] = new char[10];

   Galaxy = new NBody("OpenCL NBody");

   if (Galaxy->initialize() != SDK_SUCCESS)
      cout << "NBody initialize error" << endl;

   if (Galaxy->parseCommandLine(my_argc, my_argv) != SDK_SUCCESS)
      cout << "NBody parseCommand error" << endl;

   status = Galaxy->setup();
   if (status != SDK_SUCCESS)
      cout << "NBody setup error" << endl;

   status = Galaxy->run();  
   if(status != SDK_SUCCESS)
      cout << "Sample Run Program Failed" << endl; 

    setFormat(QGLFormat(QGL::DoubleBuffer | QGL::DepthBuffer));

    timer.start();
    m_timer = new QTimer(this);
    connect(m_timer, SIGNAL(timeout()), this, SLOT(processCurrent()));
    m_timer->start(0);  
 }

但是,当我分配一个新GLWidget对象时,因为lastPos是一个“静态”变量,所以应该没有动态内存错误。

我尝试放入lastPos私有数据成员,但问题仍然存在。

谁能解释我怎么了?

编辑1:回溯给出:

(gdb) bt
#0  0x00007ffff53501b5 in raise () from /lib/libc.so.6
#1  0x00007ffff5352fc0 in abort () from /lib/libc.so.6
#2  0x00007ffff538637b in ?? () from /lib/libc.so.6
#3  0x00007ffff538fbd6 in ?? () from /lib/libc.so.6
#4  0x00007ffff539004d in ?? () from /lib/libc.so.6
#5  0x00007ffff5392354 in ?? () from /lib/libc.so.6
#6  0x00007ffff5394a30 in malloc () from /lib/libc.so.6
#7  0x00007fffee75edec in ?? () from /usr/lib/dri/fglrx_dri.so
#8  0x00007fffee876c2f in ?? () from /usr/lib/dri/fglrx_dri.so
#9  0x00007fffee8e4e2b in ?? () from /usr/lib/dri/fglrx_dri.so
#10 0x00007fffee8e5436 in ?? () from /usr/lib/dri/fglrx_dri.so
#11 0x00007fffee879ff2 in ?? () from /usr/lib/dri/fglrx_dri.so
#12 0x00007fffee87cf94 in ?? () from /usr/lib/dri/fglrx_dri.so
#13 0x00007fffee87d0d6 in ?? () from /usr/lib/dri/fglrx_dri.so
#14 0x00007fffee614610 in ?? () from /usr/lib/dri/fglrx_dri.so
#15 0x00007fffee620783 in ?? () from /usr/lib/dri/fglrx_dri.so
#16 0x00007fffee621477 in ?? () from /usr/lib/dri/fglrx_dri.so
#17 0x00007fffee621825 in ?? () from /usr/lib/dri/fglrx_dri.so
#18 0x00007fffed98d07e in ?? () from /usr/lib/dri/fglrx_dri.so
#19 0x0000000000409164 in GLWidget::draw() ()
#20 0x0000000000409d15 in GLWidget::processCurrent() ()
#21 0x00000000004209b0 in GLWidget::qt_metacall(QMetaObject::Call, int, void**) ()
#22 0x00007ffff6d9e1f7 in QMetaObject::activate(QObject*, QMetaObject const*, int, void**) () from /usr/lib/libQtCore.so.4
#23 0x00007ffff6d97889 in QObject::event(QEvent*) () from /usr/lib/libQtCore.so.4
#24 0x00007ffff72bf4ac in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib/libQtGui.so.4
#25 0x00007ffff72c5e4d in QApplication::notify(QObject*, QEvent*) () from /usr/lib/libQtGui.so.4
#26 0x00007ffff6d864fc in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib/libQtCore.so.4
#27 0x00007ffff6db588e in ?? () from /usr/lib/libQtCore.so.4
#28 0x00007ffff6db28f4 in ?? () from /usr/lib/libQtCore.so.4
#29 0x00007ffff47bd6f2 in g_main_context_dispatch () from /lib/libglib-2.0.so.0
#30 0x00007ffff47c1568 in ?? () from /lib/libglib-2.0.so.0
#31 0x00007ffff47c171c in g_main_context_iteration () from /lib/libglib-2.0.so.0
#32 0x00007ffff6db25e3 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/libQtCore.so.4
#33 0x00007ffff73721fe in ?? () from /usr/lib/libQtGui.so.4
#34 0x00007ffff6d85222 in QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/libQtCore.so.4
#35 0x00007ffff6d8560c in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/libQtCore.so.4
#36 0x00007ffff6d896db in QCoreApplication::exec() () from /usr/lib/libQtCore.so.4
#37 0x000000000040b311 in main ()

编辑2:这是绘图功能:

 void GLWidget::draw()
{
   glClearColor(0.0 ,0.0, 0.0, 0.0);
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    if (Galaxy->isFirstLaunch)
        {
        glViewport(0, 0, w_width, w_height);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(45.0f, (float)w_width / w_height, g_nearPlane, g_farPlane);
        glMatrixMode(GL_MODELVIEW);
        gluLookAt (0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
    glScalef(0.03f, 0.03f, 0.03f);
    }
    glEnable(GL_POINT_SPRITE);
    glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
    glEnable(GL_VERTEX_PROGRAM_POINT_SIZE_NV);

    glEnable(GL_BLEND);
    glBlendFunc (GL_SRC_ALPHA, GL_ONE);    

        glUseProgram(m_program);
        glUniform1f( glGetUniformLocation(m_program, "pointRadius"), m_particleRadius );
        glUniform1f( glGetUniformLocation(m_program, "pointScale"),m_pointScale);  

        GLuint vbo_disk;

        glBindBuffer(GL_ARRAY_BUFFER, vbo_disk);
        glVertexPointer(4, GL_DOUBLE, 4*sizeof(double), Galaxy->pos);
        glEnableClientState(GL_VERTEX_ARRAY);

        glColor4f(1.0f, 1.0f, 1.0f, 0.2f);
        glDrawArrays(GL_POINTS, 0, Galaxy->getNumParticles_disk());

       glBindBuffer(GL_ARRAY_BUFFER, 0);
        glDisableClientState(GL_VERTEX_ARRAY);

    GLuint vbo_halo;

        glBindBuffer(GL_ARRAY_BUFFER, vbo_halo);
        glVertexPointer(4, GL_DOUBLE, 4*sizeof(double), &Galaxy->pos[Galaxy->getNumParticles_disk()]);
        glEnableClientState(GL_VERTEX_ARRAY);

        glColor4f(0.0f, 0.0f, 1.0f, 0.2f);
        glDrawArrays(GL_POINTS, 0, Galaxy->getNumParticles_halo());

        glBindBuffer(GL_ARRAY_BUFFER, 0);
        glDisableClientState(GL_VERTEX_ARRAY); 

        glDisable(GL_BLEND);        
    glDisable(GL_POINT_SPRITE);
}
4

0 回答 0