#Weird C++ behavior with GLFW

9 messages · Page 1 of 1 (latest)

fickle lantern
#

I've encountered a very weird behavior with c++. My code starts by reading the monitor width and height:

unsigned int width, height;
auto videoMode = glfwGetVideoMode(monitor);
width = videoMode->width; // Width is 1920
height = videoMode->height; // Height is 1080

Then I call the glfwCreateWindow function.

//GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, const char* title, GLFWmonitor* monitor, GLFWwindow* share);
window = glfwCreateWindow(width, height, "Name", monitor, share);
// width is 18
// height is 0

Note that width and height will get past as integers and not as references or pointers, so the original values should stay unchanged from my understanding. But somehow width changes to 18 and height to 0 when calling this function. What is the reason of this variable Change?

Edit: The height seems to be allways set to 0. The width seems to be set to a low random value. It also only happens, if share is set to nullptr.

maiden pollenBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

mortal granite
#

Very sure that's not the thing changing the variables, check other stuff in your code, also debuggers might help

fickle lantern
#

Well the debugger tells me that this is where the value is changed

mortal granite
#

Try assigning those values to temporary variables, pass said temporary variables to glfwCreateWindow, and print out the values of said temporary variables and see if they change the same way

fickle lantern
#

C++ be like:

#

My code:

int tmpWidth = width, tmpHeight = height;
cout << "Width1: " << tmpWidth << endl;
cout << "Height1: " << tmpHeight << endl;
window = glfwCreateWindow(tmpWidth, tmpHeight, WINDOW_NAME, monitor, share);
cout << "Width2: " << tmpWidth << endl;
cout << "Height2: " << tmpHeight << endl;

My result:

Width1: 1920
Height1: 1080
Width2: 1920
Height2: 1080
#

But then again:

unsigned int *tmpWidth = &width, *tmpHeight = &height;
cout << "Width1: " << *tmpWidth << endl;
cout << "Height1: " << *tmpHeight << endl;
window = glfwCreateWindow(*tmpWidth, *tmpHeight, WINDOW_NAME, monitor, share);
cout << "Width2: " << *tmpWidth << endl;
cout << "Height2: " << *tmpHeight << endl;

My result:

Width1: 1920
Height1: 1080
Width2: 18
Height2: 0