Я работаю над графическим интерфейсом Qt / OpenGL, который делает физическую анимацию. Я пытаюсь сделать ротацию с mousePressEvent
а также mouseMoveEvent
функции.
Для этого я пытаюсь добавить 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);
}
Задача ещё не решена.
Других решений пока нет …