Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.

Don't forget to read Tuesday's email newsletter for your chance to win a free copy of Construct 2!

glutMainLoop() causes a segmentation fault in other class...very strange

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 ShotoReaper   Members   -  Reputation: 149


Posted 14 January 2013 - 01:07 PM


I have a great problem. I have the principal class Engine.cpp with glutMainLoop(). Too I have the class PhysicsActor with the method GetPosition where occur a segmentation fault. Well, the principal problem is...That I don´t call the PhysicsActor->getPosition method in the program that at no time! When I debug from the line where I create the PhysicActor I discover that glutMainLoop() call to the method PhysicObject->getPosition() automatically, and immediately crash, without entering in  PhysicObject->getPosition() method;


The code:




Engine::Engine(int argc, char* argv[])
    Initialize(argc, argv);
    glutMainLoop();  // it calls PhysicsActor->getPosition();


void Engine::Initialize(int argc, char* argv[])
    using std::cout;
    using std::endl;
    GLenum GlewInitResult;

    InitWindow(argc, argv);

    glewExperimental = GL_TRUE;
    GlewInitResult = glewInit();

    if(GLEW_OK != GlewInitResult)
        cout<<"ERROR: "<<glewGetErrorString(GlewInitResult);

    std::cout<<"INFO: OpenGL Version: " << glGetString(GL_VERSION) <<std::endl;
    if(GL_VERSION_1_1)  //7938 = OpenGL 1.1.0
        ExitOnError("ERROR: Version de OpenGL incompatible. Actualiza tus drivers");
    glClearColor(.0f, .0f, .0f, .0f);

    ExitOnGLError("ERROR: No se puede establecer las opciones de testeo de profundidad");

    ExitOnGLError("ERROR: No se pueden establecer las opciones de culling");

    content.rootDirectory = "D:/Users/Hector Trabajo/Documents/Programacion/OpenGL/GekkoEngine_Newton/data/";


void Engine::CreateWorld(void)
    GameScreen *gs1 = new GameScreen("hola");

    Physics *phy = new Physics();

    Camera *cam = new Camera();
    cam->setPosition(glm::vec3(0.0, 2.0, 4.0));

    Cube *cb = new Cube();

    PhysicCube *pc = new PhysicCube();







glm::vec3 PhysicsActor::getPosition(void)
    if (physicObject != NULL)
        return physicObject->getPosition();  // Segmentation fault here, without entering in physicObject->getPosition() method 

        return glm::vec3(0.0f);

Can anybody help me?






#2 L. Spiro   Crossbones+   -  Reputation: 14005


Posted 14 January 2013 - 01:15 PM

You are probably corrupting your stack somewhere.

After the crash look at the stack trace and start from the bottom.  Apparently you expect glutMainLoop() to be called but somewhere along the line it is going into a function you don’t expect to be called.


I have never used GLUT and don’t know what it is “supposed” to do internally; I leave that understanding up to you.


Find the first function on the stack that seems suspicious and go to the caller of that function.  Check for memory overwrites or any possible stack corruption.



It could also be stack overflow if you have recursive calls somewhere, even if by accident.



Finally, more information always helps.  Does this happen as soon as you start?  Does it happen after a while?  Does it happen after some event?




L. Spiro

It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#3 ShotoReaper   Members   -  Reputation: 149


Posted 23 January 2013 - 02:30 PM

Thanks for the answers. I found the problem. I call indirecty the method getPosition() from the method Actor::Draw() ( Actor was the father class)


Sorry for the inconveniences

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.