diff --git a/src/internal.h b/src/internal.h index 1ca3b111..fa272524 100644 --- a/src/internal.h +++ b/src/internal.h @@ -241,6 +241,7 @@ struct _GLFWmonitor int positionY; GLFWvidmode* modes; + int modeCount; // These are defined in the current port's platform.h _GLFW_PLATFORM_MONITOR_STATE; diff --git a/src/monitor.c b/src/monitor.c index 0ae667f1..876cf9a4 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -399,10 +399,16 @@ GLFWAPI const GLFWvidmode* glfwGetVideoModes(GLFWmonitor handle, int* count) free(monitor->modes); - monitor->modes = _glfwPlatformGetVideoModes(monitor, count); + monitor->modes = _glfwPlatformGetVideoModes(monitor, &monitor->modeCount); if (monitor->modes) - qsort(monitor->modes, *count, sizeof(GLFWvidmode), compareVideoModes); + { + qsort(monitor->modes, + monitor->modeCount, + sizeof(GLFWvidmode), + compareVideoModes); + } + *count = monitor->modeCount; return monitor->modes; }