aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_gl_free_unrealized.c
diff options
context:
space:
mode:
authorJean Pierre Cimalando <jp-dev@inbox.ru>2022-05-02 21:15:28 +0200
committerDavid Robillard <d@drobilla.net>2022-05-03 16:32:50 -0400
commitd6ad1b79b97974ad3e3bd2a1b2c7474f0dd797b0 (patch)
treee6d80b6a12accd39ecc0f33b57e172f3cc21fef4 /test/test_gl_free_unrealized.c
parent7a51a9f66332f758c0b590598f0a43ad14686c5a (diff)
downloadpugl-d6ad1b79b97974ad3e3bd2a1b2c7474f0dd797b0.tar.gz
pugl-d6ad1b79b97974ad3e3bd2a1b2c7474f0dd797b0.tar.bz2
pugl-d6ad1b79b97974ad3e3bd2a1b2c7474f0dd797b0.zip
Fix crash when destroying OpenGL views that haven't been realized
Diffstat (limited to 'test/test_gl_free_unrealized.c')
-rw-r--r--test/test_gl_free_unrealized.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/test/test_gl_free_unrealized.c b/test/test_gl_free_unrealized.c
new file mode 100644
index 0000000..c4d3fcd
--- /dev/null
+++ b/test/test_gl_free_unrealized.c
@@ -0,0 +1,61 @@
+// Copyright 2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
+
+/*
+ Tests that deleting an unrealized view works properly.
+
+ This was a crash bug with OpenGL backends.
+*/
+
+#undef NDEBUG
+
+#include "test_utils.h"
+
+#include "pugl/gl.h"
+#include "pugl/pugl.h"
+
+#include <assert.h>
+#include <stdbool.h>
+#include <stddef.h>
+
+typedef struct {
+ PuglWorld* world;
+ PuglView* view;
+ PuglTestOptions opts;
+} PuglTest;
+
+static PuglStatus
+onEvent(PuglView* const view, const PuglEvent* const event)
+{
+ PuglTest* const test = (PuglTest*)puglGetHandle(view);
+
+ if (test->opts.verbose) {
+ printEvent(event, "Event: ", true);
+ }
+
+ return PUGL_SUCCESS;
+}
+
+int
+main(int argc, char** argv)
+{
+ PuglTest test = {
+ puglNewWorld(PUGL_PROGRAM, 0), NULL, puglParseTestOptions(&argc, &argv)};
+
+ // Set up view
+ test.view = puglNewView(test.world);
+ puglSetClassName(test.world, "Pugl Test");
+ puglSetWindowTitle(test.view, "Pugl Free View Test");
+ puglSetBackend(test.view, puglGlBackend());
+ puglSetHandle(test.view, &test);
+ puglSetEventFunc(test.view, onEvent);
+ puglSetDefaultSize(test.view, 512, 512);
+
+ assert(!puglGetVisible(test.view));
+
+ // Tear everything down without ever realizing the view
+ puglFreeView(test.view);
+ puglFreeWorld(test.world);
+
+ return 0;
+}