mirror of
https://github.com/glfw/glfw.git
synced 2024-11-10 00:51:47 +00:00
Fixed invalid uses of glfwDestroyWindow.
This commit is contained in:
parent
4408d2134c
commit
89018331f7
@ -34,6 +34,8 @@
|
||||
|
||||
#include "getopt.h"
|
||||
|
||||
static GLboolean closed = GL_FALSE;
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
printf("Usage: clipboard [-h]\n");
|
||||
@ -45,6 +47,12 @@ static GLboolean control_is_down(GLFWwindow window)
|
||||
glfwGetKey(window, GLFW_KEY_RIGHT_CONTROL);
|
||||
}
|
||||
|
||||
static int window_close_callback(GLFWwindow window)
|
||||
{
|
||||
closed = GL_TRUE;
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow window, int key, int action)
|
||||
{
|
||||
if (action != GLFW_PRESS)
|
||||
@ -53,7 +61,7 @@ static void key_callback(GLFWwindow window, int key, int action)
|
||||
switch (key)
|
||||
{
|
||||
case GLFW_KEY_ESCAPE:
|
||||
glfwDestroyWindow(window);
|
||||
closed = GL_TRUE;
|
||||
break;
|
||||
|
||||
case GLFW_KEY_V:
|
||||
@ -80,7 +88,7 @@ static void key_callback(GLFWwindow window, int key, int action)
|
||||
}
|
||||
}
|
||||
|
||||
static void size_callback(GLFWwindow window, int width, int height)
|
||||
static void window_size_callback(GLFWwindow window, int width, int height)
|
||||
{
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
@ -130,7 +138,8 @@ int main(int argc, char** argv)
|
||||
glfwSwapInterval(1);
|
||||
|
||||
glfwSetKeyCallback(key_callback);
|
||||
glfwSetWindowSizeCallback(size_callback);
|
||||
glfwSetWindowSizeCallback(window_size_callback);
|
||||
glfwSetWindowCloseCallback(window_close_callback);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glOrtho(-1.f, 1.f, -1.f, 1.f, -1.f, 1.f);
|
||||
@ -138,7 +147,7 @@ int main(int argc, char** argv)
|
||||
|
||||
glClearColor(0.5f, 0.5f, 0.5f, 0);
|
||||
|
||||
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
|
||||
while (!closed)
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
|
@ -37,6 +37,7 @@
|
||||
|
||||
#define STEP_SIZE 0.1f
|
||||
|
||||
static GLboolean closed = GL_FALSE;
|
||||
static GLfloat gamma_value = 1.0f;
|
||||
|
||||
static void usage(void)
|
||||
@ -51,6 +52,12 @@ static void set_gamma(float value)
|
||||
glfwSetGamma(gamma_value);
|
||||
}
|
||||
|
||||
static int window_close_callback(GLFWwindow window)
|
||||
{
|
||||
closed = GL_TRUE;
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow window, int key, int action)
|
||||
{
|
||||
if (action != GLFW_PRESS)
|
||||
@ -60,7 +67,7 @@ static void key_callback(GLFWwindow window, int key, int action)
|
||||
{
|
||||
case GLFW_KEY_ESCAPE:
|
||||
{
|
||||
glfwDestroyWindow(window);
|
||||
closed = GL_TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -145,6 +152,7 @@ int main(int argc, char** argv)
|
||||
glfwSwapInterval(1);
|
||||
|
||||
glfwSetKeyCallback(key_callback);
|
||||
glfwSetWindowCloseCallback(window_close_callback);
|
||||
glfwSetWindowSizeCallback(size_callback);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
@ -153,7 +161,7 @@ int main(int argc, char** argv)
|
||||
|
||||
glClearColor(0.5f, 0.5f, 0.5f, 0);
|
||||
|
||||
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
|
||||
while (!closed)
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
|
@ -35,11 +35,19 @@
|
||||
|
||||
#include "getopt.h"
|
||||
|
||||
static GLboolean closed = GL_FALSE;
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
printf("Usage: iconify [-h] [-f]\n");
|
||||
}
|
||||
|
||||
static int window_close_callback(GLFWwindow window)
|
||||
{
|
||||
closed = GL_TRUE;
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow window, int key, int action)
|
||||
{
|
||||
printf("%0.2f Key %s\n",
|
||||
@ -55,12 +63,12 @@ static void key_callback(GLFWwindow window, int key, int action)
|
||||
glfwIconifyWindow(window);
|
||||
break;
|
||||
case GLFW_KEY_ESCAPE:
|
||||
glfwDestroyWindow(window);
|
||||
closed = GL_TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void size_callback(GLFWwindow window, int width, int height)
|
||||
static void window_size_callback(GLFWwindow window, int width, int height)
|
||||
{
|
||||
printf("%0.2f Size %ix%i\n", glfwGetTime(), width, height);
|
||||
|
||||
@ -124,11 +132,12 @@ int main(int argc, char** argv)
|
||||
glfwSwapInterval(1);
|
||||
|
||||
glfwSetKeyCallback(key_callback);
|
||||
glfwSetWindowSizeCallback(size_callback);
|
||||
glfwSetWindowSizeCallback(window_size_callback);
|
||||
glfwSetWindowCloseCallback(window_close_callback);
|
||||
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
|
||||
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
|
||||
while (!closed)
|
||||
{
|
||||
if (iconified != glfwGetWindowParam(window, GLFW_ICONIFIED) ||
|
||||
active != glfwGetWindowParam(window, GLFW_ACTIVE))
|
||||
|
@ -35,7 +35,7 @@
|
||||
|
||||
#include "getopt.h"
|
||||
|
||||
static GLFWwindow window = NULL;
|
||||
static GLFWwindow window_handle = NULL;
|
||||
|
||||
enum Mode
|
||||
{
|
||||
@ -68,25 +68,25 @@ static void error_callback(int error, const char* description)
|
||||
fprintf(stderr, "Error: %s\n", description);
|
||||
}
|
||||
|
||||
static void window_size_callback(GLFWwindow in_window, int width, int height)
|
||||
static void window_size_callback(GLFWwindow window, int width, int height)
|
||||
{
|
||||
printf("Window resized to %ix%i\n", width, height);
|
||||
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
static int window_close_callback(GLFWwindow dummy)
|
||||
static int window_close_callback(GLFWwindow window)
|
||||
{
|
||||
window = NULL;
|
||||
window_handle = NULL;
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow dummy, int key, int action)
|
||||
static void key_callback(GLFWwindow window, int key, int action)
|
||||
{
|
||||
if (key == GLFW_KEY_ESCAPE)
|
||||
{
|
||||
glfwDestroyWindow(window);
|
||||
window = NULL;
|
||||
window_handle = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@ -132,10 +132,10 @@ static void test_modes(void)
|
||||
|
||||
printf("Testing mode %u: %s", (unsigned int) i, format_mode(mode));
|
||||
|
||||
window = glfwCreateWindow(mode->width, mode->height,
|
||||
GLFW_FULLSCREEN, "Video Mode Test",
|
||||
NULL);
|
||||
if (!window)
|
||||
window_handle = glfwCreateWindow(mode->width, mode->height,
|
||||
GLFW_FULLSCREEN, "Video Mode Test",
|
||||
NULL);
|
||||
if (!window_handle)
|
||||
{
|
||||
printf("Failed to enter mode %u: %s\n",
|
||||
(unsigned int) i,
|
||||
@ -143,7 +143,7 @@ static void test_modes(void)
|
||||
continue;
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwMakeContextCurrent(window_handle);
|
||||
glfwSwapInterval(1);
|
||||
|
||||
glfwSetTime(0.0);
|
||||
@ -151,10 +151,10 @@ static void test_modes(void)
|
||||
while (glfwGetTime() < 5.0)
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glfwSwapBuffers(window);
|
||||
glfwSwapBuffers(window_handle);
|
||||
glfwPollEvents();
|
||||
|
||||
if (!window)
|
||||
if (!window_handle)
|
||||
{
|
||||
printf("User terminated program\n");
|
||||
exit(EXIT_SUCCESS);
|
||||
@ -165,7 +165,7 @@ static void test_modes(void)
|
||||
glGetIntegerv(GL_GREEN_BITS, ¤t.greenBits);
|
||||
glGetIntegerv(GL_BLUE_BITS, ¤t.blueBits);
|
||||
|
||||
glfwGetWindowSize(window, ¤t.width, ¤t.height);
|
||||
glfwGetWindowSize(window_handle, ¤t.width, ¤t.height);
|
||||
|
||||
if (current.redBits != mode->redBits ||
|
||||
current.greenBits != mode->greenBits ||
|
||||
@ -185,9 +185,9 @@ static void test_modes(void)
|
||||
|
||||
printf("Closing window\n");
|
||||
|
||||
glfwDestroyWindow(window);
|
||||
glfwDestroyWindow(window_handle);
|
||||
window_handle = NULL;
|
||||
glfwPollEvents();
|
||||
window = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static GLboolean reopen = GL_FALSE;
|
||||
static GLFWwindow window_handle = NULL;
|
||||
static int cursor_x;
|
||||
static int cursor_y;
|
||||
@ -77,10 +78,7 @@ static void key_callback(GLFWwindow window, int key, int action)
|
||||
case GLFW_KEY_R:
|
||||
{
|
||||
if (action == GLFW_PRESS)
|
||||
{
|
||||
glfwDestroyWindow(window);
|
||||
open_window();
|
||||
}
|
||||
reopen = GL_TRUE;
|
||||
|
||||
break;
|
||||
}
|
||||
@ -121,8 +119,6 @@ int main(void)
|
||||
|
||||
if (!open_window())
|
||||
{
|
||||
glfwTerminate();
|
||||
|
||||
fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@ -135,6 +131,18 @@ int main(void)
|
||||
|
||||
glfwSwapBuffers(window_handle);
|
||||
glfwWaitEvents();
|
||||
|
||||
if (reopen)
|
||||
{
|
||||
glfwDestroyWindow(window_handle);
|
||||
if (!open_window())
|
||||
{
|
||||
fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
reopen = GL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
glfwTerminate();
|
||||
|
@ -37,27 +37,18 @@
|
||||
#define HEIGHT 400
|
||||
|
||||
static GLFWwindow windows[2];
|
||||
static GLboolean closed = GL_FALSE;
|
||||
|
||||
static void key_callback(GLFWwindow window, int key, int action)
|
||||
{
|
||||
if (action == GLFW_PRESS && key == GLFW_KEY_ESCAPE)
|
||||
glfwDestroyWindow(window);
|
||||
closed = GL_TRUE;
|
||||
}
|
||||
|
||||
static int window_close_callback(GLFWwindow window)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
if (windows[i] == window)
|
||||
{
|
||||
windows[i] = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return GL_TRUE;
|
||||
closed = GL_TRUE;
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
static GLFWwindow open_window(const char* title, GLFWwindow share)
|
||||
@ -170,7 +161,7 @@ int main(int argc, char** argv)
|
||||
glfwGetWindowPos(windows[0], &x, &y);
|
||||
glfwSetWindowPos(windows[1], x + WIDTH + 50, y);
|
||||
|
||||
while (windows[0] && windows[1])
|
||||
while (!closed)
|
||||
{
|
||||
glfwMakeContextCurrent(windows[0]);
|
||||
draw_quad(texture);
|
||||
|
Loading…
Reference in New Issue
Block a user