PDA

View Full Version : Newbie in OpenGL programming: Program starts and close immediately.



robgeek
19th August 2015, 04:20
Hello!

I'm using Arch Linux with QtCreator 3.4.2 Based on Qt 5.5.0 (GCC 5.1.0, 64 bit). So, i want to learn about OpenGL programming. To do that i installed "freeglut, mesa, mesa-demos, mesa-libgl, openal, glew". I tried make a program to show me an OpenGL example using QtCreator, but the program starts and close immediately, i don't see nothing and QtCreator doesn't show my any errot message but:

Starting /home/rob/Programming/C-C++/Linux/Qt/build-Test-Desktop-Debug/Test...
The program has unexpectedly finished.
/home/rob/Programming/C-C++/Linux/Qt/build-Test-Desktop-Debug/Test crashed

Here my code:
Test.pro

#-------------------------------------------------
#
# Project created by QtCreator 2015-08-18T11:40:04
#
#-------------------------------------------------

QT += core gui opengl

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = Test
TEMPLATE = app


SOURCES += main.cpp\
mainwindow.cpp \
glwidget.cpp

HEADERS += mainwindow.h \
glwidget.h

FORMS += mainwindow.ui

LIBS += -lglut

glwidget.h

#ifndef GLWIDGET_H
#define GLWIDGET_H

#include <QGLWidget>
#include <QObject>

class GLWidget : public QGLWidget {
Q_OBJECT

public:
explicit GLWidget(QWidget *parent = 0);

void initializeGL( );
void paintGL( );
void resizeGL(int w, int h);
};

#endif // GLWIDGET_H

mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();

private slots:
void on_pushButton_clicked();

private:
Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H

glwidget.cpp

#include "glwidget.h"
#include "GL/glut.h"

GLWidget::GLWidget(QWidget *parent) {

}

void GLWidget::initializeGL( ) {
glClearColor(0.2, 0.2, 0.2, 1);
}

void GLWidget::paintGL( ) {
glClear( GL_COLOR_BUFFER_BIT );
glRotatef(0.5, 1, 1, 1);
glutWireTeapot( 0.6 );
}

void GLWidget::resizeGL(int w, int h) {

}

main.cpp

#include "mainwindow.h"
#include "GL/glut.h"
#include <QApplication>

int main(int argc, char *argv[]) {
glutInit(&argc, argv);
QApplication a(argc, argv);
MainWindow w;
w.show( );

return a.exec( );
}

mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) : QMainWindow( parent ), ui(new Ui::MainWindow) {
ui->setupUi( this );
}

MainWindow::~MainWindow( ) {
delete ui;
}

void MainWindow::on_pushButton_clicked( ) {

}

How can i fix it?

robgeek
24th August 2015, 21:57
Sorry bump this thread, but i need help.

wysota
25th August 2015, 07:37
Show us a debugger backtrace for your program.

robgeek
25th August 2015, 15:37
One more thing i saw now.

I launched the software using terminal and i got this:

> cd Programming/C-C++/Linux/Qt/build-OpenglTest-Desktop-Debug/
> ./OpenglTest
Segmentation fault (core dumped)

wysota
26th August 2015, 08:45
Please show us the backtrace.

robgeek
4th September 2015, 14:45
I don't know if i did right.


> cd Programming/C-C++/Linux/Qt/build-Test-Desktop-Debug/
> gdb Test
GNU gdb (GDB) 7.9.1
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from Test...done.
(gdb) start
Temporary breakpoint 1 at 0x4038e6: file ../Test/main.cpp, line 6.
Starting program: /media/Backup/Programming/C-C++/Linux/Qt/build-Test-Desktop-Debug/Test
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".

Temporary breakpoint 1, main (argc=1, argv=0x7fffffffeac8) at ../Test/main.cpp:6
6 glutInit(&argc, argv);
(gdb) bt
#0 main (argc=1, argv=0x7fffffffeac8) at ../Test/main.cpp:6

Thats all i got.

anda_skoa
4th September 2015, 15:35
Almost

> gdb Test
(gdb) run

Once it crashed

(gdb) bt full

Cheers,
_

robgeek
5th September 2015, 14:57
Oh, i'm sorry!


> gdb Test
GNU gdb (GDB) 7.9.1
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from Test...done.


(gdb) run
Starting program: /media/Backup/Programming/C-C++/Linux/Qt/build-Test-Desktop-Debug/Test
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[New Thread 0x7fffe65dd700 (LWP 2817)]
[New Thread 0x7fffe9444700 (LWP 2815)]

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7b3cd06 in fghDrawGeometryWire () from /usr/lib/libglut.so.3


(gdb) bt full
#0 0x00007ffff7b3cd06 in fghDrawGeometryWire () from /usr/lib/libglut.so.3
No symbol table info available.
#1 0x00007ffff7b47a70 in ?? () from /usr/lib/libglut.so.3
No symbol table info available.
#2 0x00007ffff7b48322 in glutWireTeapot () from /usr/lib/libglut.so.3
No symbol table info available.
#3 0x0000000000404809 in GLWidget::paintGL (this=0x6c15a0) at ../Test/glwidget.cpp:15
No locals.
#4 0x00007ffff78e78e4 in QGLWidget::glDraw() () from /usr/lib/libQt5OpenGL.so.5
No symbol table info available.
#5 0x00007ffff78e728d in QGLWidget::paintEvent(QPaintEvent*) ()
from /usr/lib/libQt5OpenGL.so.5
No symbol table info available.
#6 0x00007ffff71cef08 in QWidget::event(QEvent*) () from /usr/lib/libQt5Widgets.so.5
No symbol table info available.
#7 0x00007ffff718c00c in QApplicationPrivate::notify_helper(QObject*, QEvent*) ()
from /usr/lib/libQt5Widgets.so.5
No symbol table info available.
#8 0x00007ffff71914e6 in QApplication::notify(QObject*, QEvent*) ()
from /usr/lib/libQt5Widgets.so.5
No symbol table info available.
#9 0x00007ffff645289b in QCoreApplication::notifyInternal(QObject*, QEvent*) ()
from /usr/lib/libQt5Core.so.5
No symbol table info available.
---Type <return> to continue, or q <return> to quit---
#10 0x00007ffff71c7b39 in QWidgetPrivate::sendPaintEvent(QRegion const&) ()
from /usr/lib/libQt5Widgets.so.5
No symbol table info available.
#11 0x00007ffff71c8181 in QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () from /usr/lib/libQt5Widgets.so.5
No symbol table info available.
#12 0x00007ffff7197c02 in QWidgetPrivate::repaint_sys(QRegion const&) ()
from /usr/lib/libQt5Widgets.so.5
No symbol table info available.
#13 0x00007ffff71ebc03 in ?? () from /usr/lib/libQt5Widgets.so.5
No symbol table info available.
#14 0x00007ffff718c00c in QApplicationPrivate::notify_helper(QObject*, QEvent*) ()
from /usr/lib/libQt5Widgets.so.5
No symbol table info available.
#15 0x00007ffff71914e6 in QApplication::notify(QObject*, QEvent*) ()
from /usr/lib/libQt5Widgets.so.5
No symbol table info available.
#16 0x00007ffff645289b in QCoreApplication::notifyInternal(QObject*, QEvent*) ()
from /usr/lib/libQt5Core.so.5
No symbol table info available.
#17 0x00007ffff69b2c7c in QGuiApplicationPrivate::processExposeEvent(QWindow SystemInterfacePrivate::ExposeEvent*) () from /usr/lib/libQt5Gui.so.5
No symbol table info available.
#18 0x00007ffff69b39fd in QGuiApplicationPrivate::processWindowSystemEvent(Q WindowSystem---Type <return> to continue, or q <return> to quit---
InterfacePrivate::WindowSystemEvent*) () from /usr/lib/libQt5Gui.so.5
No symbol table info available.
#19 0x00007ffff6998e38 in QWindowSystemInterface::sendWindowSystemEvents(QFl ags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/libQt5Gui.so.5
No symbol table info available.
#20 0x00007fffe83fa6b0 in ?? () from /usr/lib/libQt5XcbQpa.so.5
No symbol table info available.
#21 0x00007ffff424a9fd in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
No symbol table info available.
#22 0x00007ffff424ace0 in ?? () from /usr/lib/libglib-2.0.so.0
No symbol table info available.
#23 0x00007ffff424ad8c in g_main_context_iteration () from /usr/lib/libglib-2.0.so.0
No symbol table info available.
#24 0x00007ffff64a923f in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/libQt5Core.so.5
No symbol table info available.
#25 0x00007ffff645026a in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) ()
from /usr/lib/libQt5Core.so.5
No symbol table info available.
#26 0x00007ffff645820c in QCoreApplication::exec() () from /usr/lib/libQt5Core.so.5
No symbol table info available.
#27 0x0000000000403934 in main (argc=1, argv=0x7fffffffeac8) at ../Test/main.cpp:11
a = <incomplete type>
w = {<QMainWindow> = {<No data fields>}, static staticMetaObject = {d = {
---Type <return> to continue, or q <return> to quit---
superdata = 0x7ffff78aeee0 <QMainWindow::staticMetaObject>,
stringdata = 0x404c60 <qt_meta_stringdata_MainWindow>,
data = 0x404ce0 <qt_meta_data_MainWindow>,
static_metacall = 0x40481e <MainWindow::qt_static_metacall(QObject*, QMetaObject::Call, int, void**)>, relatedMetaObjects = 0x0, extradata = 0x0}},
ui = 0x6c0ed0}

robgeek
7th September 2015, 17:08
So, guys. What do you think!