PDA

View Full Version : application crashes with the window resize event



sajis997
11-09-2014, 10:08 AM
Hello forum;

I have the following inside the window resize callback :




void framebuffer_size_callback(GLFWwindow *window,int width,int height)
{

if(height < 1)
height = 1;

winWidth = width;
winHeight = height;


//set the viewport matrix
ViewportMatrix = glm::mat4(glm::vec4((GLfloat)winWidth/2.0f,0.0f,0.0f,0.0f),
glm::vec4(0.0f,(GLfloat)winHeight/2.0f,0.0f,0.0f),
glm::vec4(0.0f,0.0f,1.0f,0.0f),
glm::vec4((GLfloat)winWidth/2.0f,(GLfloat)winHeight/2.0f,0.0f,1.0f));

//setup the projection matrix
ProjectionMatrix = glm::perspective(50.0f,(GLfloat)(winWidth/winHeight),0.1f,1000.0f);

glViewport(0,0,winWidth,winHeight);
}



And i have called the above in the following manner inside the main function:




......................
......................
glfwSetErrorCallback(error_callback);
glfwSetFramebufferSizeCallback(window,framebuffer_ size_callback);
glfwSetScrollCallback(window,scroll_callback);
glfwSetKeyCallback(window,key_callback);


//make the current window context the current one
glfwMakeContextCurrent(window);
glfwSwapInterval(1);

glfwGetFramebufferSize(window,&winWidth,&winHeight);
framebuffer_size_callback(window,winWidth,winHeigh t);

......................
......................


I am having the following error :



**************** OpenGL Driver Information *********************
OpenGL version: 4.4.0 NVIDIA 340.46
GLSL version: 4.40 NVIDIA via Cg compiler
GLEW version: 1.10.0
OpenGL vendor: NVIDIA Corporation
Renderer: GeForce GTX 560M/PCIe/SSE2
************************************************** **************
SolidWiredFrame: /usr/include/glm/gtc/matrix_transform.inl:247: glm::detail::tmat4x4<T, (glm::precision)0u> glm::perspective(const valType&, const valType&, const valType&, const valType&) [with valType = float]: Assertion `aspect != valType(0)' failed.



it is pointing to the opengl mathematics library i am using to do all the affine transformation. Any idea ?

GClements
11-10-2014, 12:35 AM
I have the following inside the window resize callback :


ProjectionMatrix = glm::perspective(50.0f,(GLfloat)(winWidth/winHeight),0.1f,1000.0f);


I am having the following error :


SolidWiredFrame: /usr/include/glm/gtc/matrix_transform.inl:247: glm::detail::tmat4x4<T, (glm::precision)0u> glm::perspective(const valType&, const valType&, const valType&, const valType&) [with valType = float]: Assertion `aspect != valType(0)' failed.


It's complaining that you're passing zero for the "aspect" parameter of glm::perspective.

This will occur if winWidth and winHeight are both integers and winWidth is less than winHeight. If you want the ratio as a floating-point value, you have to convert at least one of them to floating point prior to division. Your existing code divides to integers which produces an integer result (in this case, zero), which you then convert to floating point.

This is a C++ problem, unrelated to OpenGL.

DragonForce99
11-10-2014, 02:45 AM
yes i got this problem beffor and i found out that i'v allo allocated arra[3] am while i am using 4
just like what "GClements" said This is a C++ problem, unrelated to OpenGL.