aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pugl/pugl_internal.h4
-rw-r--r--pugl/pugl_osx.m14
-rw-r--r--pugl/pugl_win.cpp15
-rw-r--r--pugl/pugl_x11.c19
4 files changed, 31 insertions, 21 deletions
diff --git a/pugl/pugl_internal.h b/pugl/pugl_internal.h
index 981c0fb..15e2f0a 100644
--- a/pugl/pugl_internal.h
+++ b/pugl/pugl_internal.h
@@ -24,7 +24,7 @@
#include "pugl.h"
-typedef struct PuglPlatformDataImpl PuglPlatformData;
+typedef struct PuglInternalsImpl PuglInternals;
struct PuglViewImpl {
PuglHandle handle;
@@ -37,7 +37,7 @@ struct PuglViewImpl {
PuglScrollFunc scrollFunc;
PuglSpecialFunc specialFunc;
- PuglPlatformData* impl;
+ PuglInternals* impl;
int width;
int height;
diff --git a/pugl/pugl_osx.m b/pugl/pugl_osx.m
index 2f4a0e9..b3b6bae 100644
--- a/pugl/pugl_osx.m
+++ b/pugl/pugl_osx.m
@@ -216,7 +216,7 @@ getModifiers(unsigned modifierFlags)
@end
-struct PuglPlatformDataImpl {
+struct PuglInternalsImpl {
PuglOpenGLView* view;
NSModalSession session;
id window;
@@ -229,14 +229,16 @@ puglCreate(PuglNativeWindow parent,
int height,
bool resizable)
{
- PuglView* view = (PuglView*)calloc(1, sizeof(PuglView));
+ PuglView* view = (PuglView*)calloc(1, sizeof(PuglView));
+ PuglInternals* impl = (PuglInternals*)calloc(1, sizeof(PuglInternals));
+ if (!view || !impl) {
+ return NULL;
+ }
+
+ view->impl = impl;
view->width = width;
view->height = height;
- view->impl = (PuglPlatformData*)calloc(1, sizeof(PuglPlatformData));
-
- PuglPlatformData* impl = view->impl;
-
[NSAutoreleasePool new];
[NSApplication sharedApplication];
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
diff --git a/pugl/pugl_win.cpp b/pugl/pugl_win.cpp
index cc69036..63d484f 100644
--- a/pugl/pugl_win.cpp
+++ b/pugl/pugl_win.cpp
@@ -24,7 +24,7 @@
#include "pugl_internal.h"
-struct PuglPlatformDataImpl {
+struct PuglInternalsImpl {
HWND hwnd;
HDC hdc;
HGLRC hglrc;
@@ -58,11 +58,15 @@ puglCreate(PuglNativeWindow parent,
int height,
bool resizable)
{
- PuglView* view = (PuglView*)calloc(1, sizeof(PuglView));
-
- view->impl = (PuglPlatformData*)calloc(1, sizeof(PuglPlatformData));
+ PuglView* view = (PuglView*)calloc(1, sizeof(PuglView));
+ PuglInternals* impl = (PuglInternals*)calloc(1, sizeof(PuglInternals));
+ if (!view || !impl) {
+ return NULL;
+ }
- PuglPlatformData* impl = view->impl;
+ view->impl = impl;
+ view->width = width;
+ view->height = height;
WNDCLASS wc;
wc.style = CS_OWNDC;
@@ -113,6 +117,7 @@ puglDestroy(PuglView* view)
wglDeleteContext(view->impl->hglrc);
ReleaseDC(view->impl->hwnd, view->impl->hdc);
DestroyWindow(view->impl->hwnd);
+ free(view->impl);
free(view);
}
diff --git a/pugl/pugl_x11.c b/pugl/pugl_x11.c
index dde2b23..f3debec 100644
--- a/pugl/pugl_x11.c
+++ b/pugl/pugl_x11.c
@@ -31,7 +31,7 @@
#include "pugl_internal.h"
-struct PuglPlatformDataImpl {
+struct PuglInternalsImpl {
Display* display;
int screen;
Window win;
@@ -72,12 +72,13 @@ puglCreate(PuglNativeWindow parent,
int height,
bool resizable)
{
- PuglView* view = (PuglView*)calloc(1, sizeof(PuglView));
-
- view->impl = (PuglPlatformData*)calloc(1, sizeof(PuglPlatformData));
-
- PuglPlatformData* impl = view->impl;
+ PuglView* view = (PuglView*)calloc(1, sizeof(PuglView));
+ PuglInternals* impl = (PuglInternals*)calloc(1, sizeof(PuglInternals));
+ if (!view || !impl) {
+ return NULL;
+ }
+ view->impl = impl;
view->width = width;
view->height = height;
@@ -85,7 +86,7 @@ puglCreate(PuglNativeWindow parent,
impl->screen = DefaultScreen(impl->display);
XVisualInfo* vi = glXChooseVisual(impl->display, impl->screen, attrListDbl);
- if (vi == NULL) {
+ if (!vi) {
vi = glXChooseVisual(impl->display, impl->screen, attrListSgl);
impl->doubleBuffered = False;
printf("singlebuffered rendering will be used, no doublebuffering available\n");
@@ -149,6 +150,8 @@ puglCreate(PuglNativeWindow parent,
printf("no DRI available\n");
}
+ XFree(vi);
+
return view;
}
@@ -159,10 +162,10 @@ puglDestroy(PuglView* view)
return;
}
- glXMakeCurrent(view->impl->display, None, NULL);
glXDestroyContext(view->impl->display, view->impl->ctx);
XDestroyWindow(view->impl->display, view->impl->win);
XCloseDisplay(view->impl->display);
+ free(view->impl);
free(view);
}