Hi!
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.cpp
Engine::Engine(int argc, char* argv[])
{
//ctor
Initialize(argc, argv);
glutMainLoop(); // it calls PhysicsActor->getPosition();
exit(EXIT_SUCCESS);
}
//Destructor
Engine::~Engine()
{
//dtor
}
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);
exit(EXIT_FAILURE);
}
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");
}*/
glGetError();
glClearColor(.0f, .0f, .0f, .0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
ExitOnGLError("ERROR: No se puede establecer las opciones de testeo de profundidad");
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glFrontFace(GL_CCW);
ExitOnGLError("ERROR: No se pueden establecer las opciones de culling");
content.rootDirectory = "D:/Users/Hector Trabajo/Documents/Programacion/OpenGL/GekkoEngine_Newton/data/";
CreateWorld();
}
void Engine::CreateWorld(void)
{
GameScreen *gs1 = new GameScreen("hola");
PushGameScreen(gs1);
Physics *phy = new Physics();
gs1->AddComponent(phy);
Camera *cam = new Camera();
gs1->AddComponent(cam);
cam->setPosition(glm::vec3(0.0, 2.0, 4.0));
Cube *cb = new Cube();
gs1->AddComponent(cb);
cb->setPosition(glm::vec3(1.2f));
cb->setScale(glm::vec3(.2f));
PhysicCube *pc = new PhysicCube();
gs1->AddComponent(pc)
}
PhysicsActor.cpp
glm::vec3 PhysicsActor::getPosition(void)
{
if (physicObject != NULL)
{
return physicObject->getPosition(); // Segmentation fault here, without entering in physicObject->getPosition() method
}else{
return glm::vec3(0.0f);
}
}
Can anybody help me?