fix the whole mutex shito

fixes potential crash when resizing window
This commit is contained in:
StapleButter 2019-05-31 04:15:37 +02:00
parent d8d7ba9251
commit 464b116916
5 changed files with 28 additions and 73 deletions

View File

@ -3,6 +3,18 @@
extern GThread* gtkthread;
// notes:
// - G_DECLARE_DERIVABLE/FINAL_INTERFACE() requires glib 2.44 and that's starting with debian stretch (testing) (GTK+ 3.18) and ubuntu 15.04 (GTK+ 3.14) - debian jessie has 2.42 (GTK+ 3.14)
#define areaWidgetType (areaWidget_get_type())
#define areaWidget(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), areaWidgetType, areaWidget))
#define isAreaWidget(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), areaWidgetType))
#define areaWidgetClass(class) (G_TYPE_CHECK_CLASS_CAST((class), areaWidgetType, areaWidgetClass))
#define isAreaWidgetClass(class) (G_TYPE_CHECK_CLASS_TYPE((class), areaWidget))
#define getAreaWidgetClass(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), areaWidgetType, areaWidgetClass))
typedef struct areaWidget areaWidget;
typedef struct areaWidgetClass areaWidgetClass;
struct areaWidget {
GtkDrawingArea parent_instance;
uiArea *a;
@ -131,22 +143,6 @@ static void loadAreaSize(uiArea *a, double *width, double *height)
}
}
void areaPreRedraw(areaWidget* widget)
{
uiArea* a = widget->a;
if (!a->opengl) return;
areaPreRedrawGL(a->glContext);
}
void areaPostRedraw(areaWidget* widget)
{
uiArea* a = widget->a;
if (!a->opengl) return;
areaPostRedrawGL(a->glContext);
}
static gboolean areaWidget_draw(GtkWidget *w, cairo_t *cr)
{
areaWidget *aw = areaWidget(w);

View File

@ -6,6 +6,7 @@
void* glXGetProcAddressARB(const GLubyte* name);
extern GThread* gtkthread;
extern GMutex glmutex;
struct uiGLContext
{
@ -15,8 +16,6 @@ struct uiGLContext
GdkGLContext *gctx;
int vermaj, vermin;
GMutex mutex;
int width, height;
int scale;
GLuint renderbuffer[2][2];
@ -96,8 +95,6 @@ uiGLContext *createGLContext(GtkWidget* widget, int maj, int min)
areaAllocRenderbuffer(ctx);
ctx->backbuffer = 0;
g_mutex_init(&ctx->mutex);
ctx->widget = widget;
ctx->window = gdkwin;
ctx->gctx = gctx;
@ -144,7 +141,7 @@ static void areaAllocRenderbuffer(uiGLContext* glctx)
// printf("FRAMEBUFFER IS BAD!! %04X\n", _glCheckFramebufferStatus(GL_FRAMEBUFFER));
}
static void areaRellocRenderbuffer(uiGLContext* glctx)
static void areaReallocRenderbuffer(uiGLContext* glctx)
{
_glBindRenderbuffer(GL_RENDERBUFFER, glctx->renderbuffer[0][0]);
_glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB, glctx->width*glctx->scale, glctx->height*glctx->scale);
@ -157,16 +154,6 @@ static void areaRellocRenderbuffer(uiGLContext* glctx)
//_glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_STENCIL, glctx->width*glctx->scale, glctx->height*glctx->scale);
}
void areaPreRedrawGL(uiGLContext* glctx)
{
g_mutex_lock(&glctx->mutex);
}
void areaPostRedrawGL(uiGLContext* glctx)
{
g_mutex_unlock(&glctx->mutex);
}
void areaDrawGL(GtkWidget* widget, uiAreaDrawParams* dp, cairo_t* cr, uiGLContext* glctx)
{
int window_scale = gdk_window_get_scale_factor(glctx->window);
@ -176,12 +163,14 @@ void areaDrawGL(GtkWidget* widget, uiAreaDrawParams* dp, cairo_t* cr, uiGLContex
glctx->width = dp->AreaWidth;
glctx->height = dp->AreaHeight;
glctx->scale = window_scale;
areaRellocRenderbuffer(glctx);
areaReallocRenderbuffer(glctx);
}
else
{
gdk_cairo_draw_from_gl(cr, gtk_widget_get_window(widget),
glctx->renderbuffer[glctx->backbuffer][0], GL_RENDERBUFFER,
1, 0, 0, glctx->width*glctx->scale, glctx->height*glctx->scale);
}
}
int uiGLGetFramebuffer(uiGLContext* ctx)
@ -215,7 +204,7 @@ void uiGLBegin(uiGLContext* ctx)
{
if (g_thread_self() != gtkthread)
{
g_mutex_lock(&ctx->mutex);
g_mutex_lock(&glmutex);
}
}
@ -223,7 +212,7 @@ void uiGLEnd(uiGLContext* ctx)
{
if (g_thread_self() != gtkthread)
{
g_mutex_unlock(&ctx->mutex);
g_mutex_unlock(&glmutex);
}
}

View File

@ -5,25 +5,17 @@ uiInitOptions options;
// kind of a hack
GThread* gtkthread;
GMutex glmutex;
int boub(GtkWidget* w);
void baba(GtkWidget* w);
static void _eventfilter(GdkEvent* evt, gpointer data)
{
if (evt->type == GDK_EXPOSE)
{
GtkWidget* widget = gtk_get_event_widget(evt);
if (isAreaWidget(widget))
{
areaWidget* area = areaWidget(widget);
areaPreRedraw(area);
g_mutex_lock(&glmutex);
gtk_main_do_event(evt);
areaPostRedraw(area);
g_mutex_unlock(&glmutex);
return;
}
}
gtk_main_do_event(evt);
}
@ -48,6 +40,7 @@ const char *uiInit(uiInitOptions *o)
loadFutures();
gtkthread = g_thread_self();
g_mutex_init(&glmutex);
GList* iconlist = NULL;
iconlist = g_list_append(iconlist, gdk_pixbuf_new_from_resource("/org/kuriboland/melonDS/icon/melon_16x16.png", NULL));

View File

@ -67,22 +67,5 @@ extern gboolean FUTURE_gtk_widget_path_iter_set_object_name(GtkWidgetPath *path,
// gl.c
extern uiGLContext *createGLContext(GtkWidget* widget, int maj, int min);
extern void freeGLContext(uiGLContext* glctx);
extern void areaPreRedrawGL(uiGLContext* glctx);
extern void areaDrawGL(GtkWidget* widget, uiAreaDrawParams* dp, cairo_t* cr, uiGLContext* glctx);
extern void areaPostRedrawGL(uiGLContext* glctx);
// notes:
// - G_DECLARE_DERIVABLE/FINAL_INTERFACE() requires glib 2.44 and that's starting with debian stretch (testing) (GTK+ 3.18) and ubuntu 15.04 (GTK+ 3.14) - debian jessie has 2.42 (GTK+ 3.14)
#define areaWidgetType (areaWidget_get_type())
#define areaWidget(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), areaWidgetType, areaWidget))
#define isAreaWidget(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), areaWidgetType))
#define areaWidgetClass(class) (G_TYPE_CHECK_CLASS_CAST((class), areaWidgetType, areaWidgetClass))
#define isAreaWidgetClass(class) (G_TYPE_CHECK_CLASS_TYPE((class), areaWidget))
#define getAreaWidgetClass(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), areaWidgetType, areaWidgetClass))
typedef struct areaWidget areaWidget;
typedef struct areaWidgetClass areaWidgetClass;
extern void areaPreRedraw(areaWidget* widget);
extern void areaPostRedraw(areaWidget* widget);

View File

@ -430,12 +430,6 @@ void GLScreen_DrawScreen()
uiGLSwapBuffers(GLContext);
}
void norp(void* data)
{
uiGLMakeContextCurrent(GLContext);
GLScreen_DrawScreen();
}
void MicLoadWav(char* name)
{
SDL_AudioSpec format;