View unanswered posts | View active topics It is currently Thu May 24, 2018 6:08 am



Reply to topic  [ 1 post ] 
 Program crash unexpectedly!! 
Author Message

Joined: Sat Jan 10, 2015 12:44 am
Posts: 1
Post Program crash unexpectedly!!
Hi , I am trying to build a 3D printer software and I want to use the GLC_lib to handle the model display and manipulation so I downloaded the source code , built it and tried the examples and it worked fine.

I even modified some code in example 6 to let me load 3ds,obj and stl models and it all worked fine but I figured that I will need to load the textures manually which aren't needed in the software anyway.

the problem now is that when I tried to write some code to do that in an embedded widget in my mainwindow in Qt , the program crash after the debugging message "GLC_Context::choose_Context" which happens in mainwindow constructor so the mainwindow doesn't even get displayed!


.pro
Code:
#-------------------------------------------------
#
# Project created by QtCreator 2014-12-18T23:56:20
#
#-------------------------------------------------

QT       += core gui
QT       += opengl

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = 3DPrinter
TEMPLATE = app

LIBS += C:/GLC_lib-2.5/lib/libGLC_lib2.a

INCLUDEPATH += C:/GLC_lib-2.5/include

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

HEADERS  += mainwindow.h \
    const.h \
    glwidget.h

FORMS    += mainwindow.ui

RESOURCES += \
    resoruces.qrc




glwidget.h
Code:
#ifndef GLWIDGET_H
#define GLWIDGET_H

//////////////////////////// GLC specific///////////////////////////////////////
// The factory
#include <GLC_Factory>
// Light
#include <GLC_Light>
// Material
#include <GLC_Material>
// The Viewport with a default camera
#include <GLC_Viewport>
// The World which manage GLC_object
#include <GLC_World>
// The Mover controller is used to change the point of view
#include <GLC_MoverController>

//////////////////////////End GLC specific/////////////////////////////////////

#include <QGLWidget>


class GLWidget : public QGLWidget
{
public:
    GLWidget(QWidget *parent);
    ~GLWidget();

    //World manipulations
    void AddObjectToWorld(GLC_Object*);
    void RemoveObjectFromWorld(int UniqueID);
    void GenerateSupportSturctureToObject(int UniqueID);
    void RemoveSupportSturctureOfObject(int UniqueID);

protected:
    void initializeGL();
    void paintGL();
    void resizeGL(int width, int height);


    void CreateScene();

    //Mouse events
    void mousePressEvent(QMouseEvent *e);
    void mouseMoveEvent(QMouseEvent *e);
    void mouseReleaseEvent(QMouseEvent *e);

private:
    GLC_Light m_Light;
    GLC_World m_World;
    GLC_Viewport m_GlView;
    GLC_MoverController m_MoverController;
};

#endif // GLWIDGET_H




glwidget.cpp
Code:
#include <QtDebug>
#include <QFile>

#include <GLC_UserInput>
#include <GLC_Context>

#include "glwidget.h"

// For VSYNC problem under Mac OS X
#if defined(Q_OS_MAC)
#include <OpenGL.h>
#endif

GLWidget::GLWidget(QWidget *parent)
    : QGLWidget(new GLC_Context(QGLFormat(QGL::SampleBuffers)), parent) [b]//The program crash here!!![/b]
    , m_Light()
    , m_GlView()
    , m_MoverController()
{
    qDebug() << "Initialized member variables.";
    //////////////////////////// GLC specific///////////////////////////////////////
        connect(&m_GlView, SIGNAL(updateOpenGL()), this, SLOT(updateGL()));
        m_Light.setPosition(1.0, 1.0, 1.0);

        QColor repColor;
        repColor.setRgbF(1.0, 0.11372, 0.11372, 1.0);
        m_MoverController= GLC_Factory::instance()->createDefaultMoverController(repColor, &m_GlView);

        qDebug() << "Creating Scene...";
        // Create objects to display
        CreateScene();

        qDebug() << " Scene created successfully";

    //////////////////////////End GLC specific/////////////////////////////////////

}

GLWidget::~GLWidget()
{

}

void GLWidget::initializeGL()
{

    // For VSYNC problem under Mac OS X
    #if defined(Q_OS_MAC)
    const GLint swapInterval = 1;
    CGLSetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &swapInterval);
    #endif

    // OpenGL initialisation
    m_GlView.initGl();

    // Load background image
    //m_GlView.loadBackGroundImage(":/Scene/C:/Users/Mohammed/Desktop/software examples/box-icon.jpg");

    // Reframe the scene on the loaded mesh
    m_GlView.reframe(m_World.boundingBox());


}

void GLWidget::paintGL()
{

    // Clear screen
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Load identity matrix
    GLC_Context::current()->glcLoadIdentity();

    // Calculate camera depth of view
    m_GlView.setDistMinAndMax(m_World.boundingBox());

    // define the light
    m_Light.glExecute();

    // define view matrix
    m_GlView.glExecuteCam();

    // Render the scene
    m_World.render(0, glc::ShadingFlag);
    m_World.render(0, glc::TransparentRenderFlag);

    // Display UI Info (orbit circle)
    m_MoverController.drawActiveMoverRep();


}

void GLWidget::resizeGL(int width, int height)
{
    m_GlView.setWinGLSize(width, height);   // Compute window aspect ratio
}


void GLWidget::CreateScene()
{
    // Load mesh from a file
    QFile manFile(":/Scene/Resources/models/superboy/superboy.obj");
    m_World= GLC_Factory::instance()->createWorldFromFile(manFile);

}


void GLWidget::mousePressEvent(QMouseEvent *e)
{
    if (m_MoverController.hasActiveMover()) return;
    switch (e->button())
    {
    case (Qt::RightButton):
        m_MoverController.setActiveMover(GLC_MoverController::TrackBall, GLC_UserInput(e->x(), e->y()));
        updateGL();
        break;
    case (Qt::LeftButton):
        m_MoverController.setActiveMover(GLC_MoverController::Pan, GLC_UserInput(e->x(), e->y()));
        updateGL();
        break;
    case (Qt::MidButton):
        m_MoverController.setActiveMover(GLC_MoverController::Zoom, GLC_UserInput(e->x(), e->y()));
        updateGL();
        break;

    default:
        break;
    }
}

void GLWidget::mouseMoveEvent(QMouseEvent * e)
{
    if (m_MoverController.hasActiveMover())
    {
        m_MoverController.move(GLC_UserInput(e->x(), e->y()));
        m_GlView.setDistMinAndMax(m_World.boundingBox());
        updateGL();
    }
}

void GLWidget::mouseReleaseEvent(QMouseEvent*)
{
    if (m_MoverController.hasActiveMover())
    {
        m_MoverController.setNoMover();
        updateGL();
    }
}


mainwindow.h
Code:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

//#include "glwidget.h"

class GLWidget;

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

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

protected slots:

    //ToolBar's Actions recievers
    void OpenModel();
    void SaveScene();
    void ConnectToPrinter();
    void DisconnectPrinter();
    void Slice();
    void Print();
    void PausePrinting();
    void StopPrinting();
    void Options();

protected:

    void resizeEvent(QResizeEvent* event);

private:
    Ui::MainWindow *ui;
    GLWidget *p_GLWidget;
};

#endif // MAINWINDOW_H



mainwindow.cpp
Code:
#include "mainwindow.h"
#include "ui_mainwindow.h"

#include "const.h"
#include "glwidget.h"

#include <QIcon>


MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow),
    p_GLWidget(NULL)
{
    setWindowState(Qt::WindowMaximized);


    ui->setupUi(this);

    ui->mainToolBar->setIconSize(QSize(48,48));

    //ToolBar's Buttons
    ui->mainToolBar->addAction(QIcon(":/ToolBar/Resources/imgs/Open.ico"),tr("Open 3D Model"),this,SLOT(OpenModel()));
    ui->mainToolBar->addAction(QIcon(":/ToolBar/Resources/imgs/Save.ico"),tr("Save Scene"),this,SLOT(SaveScene()));
    ui->mainToolBar->addSeparator();

    ui->mainToolBar->addAction(QIcon(":/ToolBar/Resources/imgs/connect.ico"),tr("Connect to Printer"),this,SLOT(ConnectToPrinter()));
    ui->mainToolBar->addAction(QIcon(":/ToolBar/Resources/imgs/disconnect.ico"),tr("Disconnect Printer"),this,SLOT(DisconnectPrinter()));
    ui->mainToolBar->addSeparator();

    ui->mainToolBar->addAction(QIcon(":/ToolBar/Resources/imgs/Play.ico"),tr("Start Printing"),this,SLOT(Print()));
    ui->mainToolBar->addAction(QIcon(":/ToolBar/Resources/imgs/Pause.ico"),tr("Pause Printing"),this,SLOT(PausePrinting()));
    ui->mainToolBar->addAction(QIcon(":/ToolBar/Resources/imgs/Stop.ico"),tr("Stop Printing"),this,SLOT(StopPrinting()));
    ui->mainToolBar->addSeparator();

    ui->mainToolBar->addAction(QIcon(":/ToolBar/Resources/imgs/Layers.ico"),tr("Slice"),this,SLOT(Slice()));
    ui->mainToolBar->addAction(QIcon(":/ToolBar/Resources/imgs/options.ico"),tr("Options"),this,SLOT(Options()));

    p_GLWidget = new GLWidget(this);
    ui->Scenewidget = p_GLWidget; //Scenewidget is a QWidget in the mainwindow ui

}

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

void MainWindow::OpenModel()
{

}

void MainWindow::SaveScene()
{

}

void MainWindow::ConnectToPrinter()
{

}

void MainWindow::DisconnectPrinter()
{

}

void MainWindow::Slice()
{

}

void MainWindow::Print()
{

}

void MainWindow::PausePrinting()
{

}

void MainWindow::StopPrinting()
{

}

void MainWindow::Options()
{

}

void MainWindow::resizeEvent(QResizeEvent *event)
{
    QMainWindow::resizeEvent(event);

    int width = this->width();
    int height = this->height();

    ui->Scenewidget->setGeometry(width*SceneFromHorizntalEdgeDistance,
                                 height*SceneFromVerticalEdgeDistance,
                                 width*SceneWidthToWindowWidth,
                                 height*SceneHeightToWindowHeight);

    ui->toolBox->setGeometry(width*ToolBoxFromHorizntalDistance,
                             height*ToolBoxFromVerticalDistance,
                             ui->toolBox->width(),
                             ui->toolBox->height());

}




NOTE: Operating system : Windows 7
Qt version : 5.4.0


Sun Jan 11, 2015 12:32 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.