aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/meson.build3
-rw-r--r--test/test_gl_free_unrealized.c61
2 files changed, 63 insertions, 1 deletions
diff --git a/test/meson.build b/test/meson.build
index d8b27a9..e16e818 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -65,7 +65,8 @@ cairo_tests = [
gl_tests = [
'gl',
- 'gl_hints'
+ 'gl_free_unrealized',
+ 'gl_hints',
]
vulkan_tests = [
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;
+}