View Full Version : Glm::lookAt crash

03-03-2014, 01:23 PM

I recently have experienced crash using glm::lookAt function. I'm not sure what is wrong, but it occurs only when I pass camera location and target both with the same Z value. For example camera location to be (0, 0, 4) and target (0, -1, 4) and to have every argument, the up vector is also (0, 1, 0).
Is it me doing something wrong, or it's just the glm's bug? In either case, what should be done to avoid the crash?
The error message is:

Terminate called after throwing an instance of 'std::logic_error' what(): basic_string::_$_construct null not valid


Dark Photon
03-03-2014, 05:02 PM
The problem is that your "look_toward" vector is colinear with your "up" vector.

look_toward = normalize( target - camera_loc ) = vec3( 0,-1,0 )

With this, LookAt can't define an orthonormal coordinate frame.

03-04-2014, 01:20 AM
So what should be done if I want to look straight up or down? No idea for a solution actually comes to my head.

Dark Photon
03-04-2014, 05:51 AM
Pass a camera "up" vector that is pointing north, or south, or east, or ... Along the ground anyway.

Keep in mind when you say "look straight up" you are talking about WORLD space, not EYE space. With gluLookAt, you are providing vectors in WORLD space to orient and position EYE space.