Monitor enumeration fixes.

This commit is contained in:
Camilla Berglund 2013-06-09 13:07:23 +02:00
parent c8166e58d3
commit 68b7ea86d2
4 changed files with 25 additions and 11 deletions

View File

@ -307,6 +307,8 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
_glfwInputError(GLFW_PLATFORM_ERROR,
"Cocoa: Failed to find NSScreen for CGDisplay %s",
monitors[i]->name);
free(monitors);
return NULL;
}
}

View File

@ -131,7 +131,7 @@ GLFWAPI int glfwInit(void)
}
_glfw.monitors = _glfwPlatformGetMonitors(&_glfw.monitorCount);
if (_glfw.monitors == NULL || _glfw.monitorCount == 0)
if (_glfw.monitors == NULL)
{
_glfwErrorCallback(GLFW_PLATFORM_ERROR, "No monitors found");
_glfwPlatformTerminate();

View File

@ -107,6 +107,8 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
DWORD adapterIndex = 0;
int primaryIndex = 0;
*count = 0;
for (;;)
{
DISPLAY_DEVICE adapter, display;
@ -152,6 +154,8 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
_glfwDestroyMonitors(monitors, found);
_glfwInputError(GLFW_PLATFORM_ERROR,
"Failed to convert string to UTF-8");
free(monitors);
return NULL;
}

View File

@ -162,15 +162,15 @@ void _glfwRestoreVideoMode(_GLFWmonitor* monitor)
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
_GLFWmonitor** _glfwPlatformGetMonitors(int* found)
_GLFWmonitor** _glfwPlatformGetMonitors(int* count)
{
_GLFWmonitor** monitors = NULL;
*found = 0;
*count = 0;
if (_glfw.x11.randr.available)
{
int i;
int i, found = 0;
RROutput primary;
XRRScreenResources* sr;
@ -206,21 +206,21 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* found)
continue;
}
monitors[*found] = _glfwCreateMonitor(oi->name,
oi->mm_width, oi->mm_height);
monitors[found] = _glfwCreateMonitor(oi->name,
oi->mm_width, oi->mm_height);
monitors[*found]->x11.output = output;
monitors[*found]->x11.crtc = oi->crtc;
monitors[found]->x11.output = output;
monitors[found]->x11.crtc = oi->crtc;
XRRFreeOutputInfo(oi);
XRRFreeCrtcInfo(ci);
(*found)++;
found++;
}
XRRFreeScreenResources(sr);
for (i = 0; i < *found; i++)
for (i = 0; i < found; i++)
{
if (monitors[i]->x11.output == primary)
{
@ -230,6 +230,14 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* found)
break;
}
}
if (found == 0)
{
free(monitors);
monitors = NULL;
}
*count = found;
}
else
{
@ -239,7 +247,7 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* found)
_glfw.x11.screen),
DisplayHeightMM(_glfw.x11.display,
_glfw.x11.screen));
*found = 1;
*count = 1;
}
return monitors;