From 0f44dfdde84cc64f0b013d6154fe4f14ea7c3436 Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Mon, 26 Dec 2011 14:46:22 +0100 Subject: [PATCH] test_console: fix console deinitialization bug We must not destroy the compositor object if there is still a console using the GL context. Otherwise we get a SEGFAULT when calling any gl* function. In future we may need propoper dependencies here. We use reference counts so this should be easy to implement. Signed-off-by: David Herrmann --- TODO | 5 ++++- src/console.c | 5 +++++ tests/test_console.c | 10 +++++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/TODO b/TODO index e6877ac..9f21ad4 100644 --- a/TODO +++ b/TODO @@ -8,7 +8,10 @@ Output Subsystem: you have only one card, multiple active contexts are not really needed. - Avoid EGL_EGLEXT_PROTOTYPES and GL_GLEXT_PROTOTYPES and instead retrieve - function pointers dynamically. + function pointers dynamically. This may also fix invalid function pointers if + no GL context is available and we deinitialize the console subsystem. Or we + may need to use proper dependencies here. The GL context shouldn't be + destroyed as long as a console uses it. - How to get bpp and colordepth? diff --git a/src/console.c b/src/console.c index 2ed88b6..38cdb1e 100644 --- a/src/console.c +++ b/src/console.c @@ -233,6 +233,11 @@ unsigned int kmscon_console_get_height(struct kmscon_console *con) * Pass 0 for each parameter if you want to use the current value. Therefore: * kmscon_console_resize(con, 0, 0, 0) has no effect as it doesn't change * anything. + * If you called this once you must make sure that the GL context stays alive + * for as long as this console object does. Otherwise, on deinitialization we + * may call invalid OpenGL functions. + * TODO: Use proper dependencies here. Maybe pass in a kmscon_output or similar + * so we correctly activate GL contexts. */ int kmscon_console_resize(struct kmscon_console *con, unsigned int x, unsigned int y, unsigned int height) diff --git a/tests/test_console.c b/tests/test_console.c index a327801..11bd149 100644 --- a/tests/test_console.c +++ b/tests/test_console.c @@ -249,8 +249,8 @@ static void destroy_eloop(struct console *con) { kmscon_eloop_rm_idle(con->idle); kmscon_idle_unref(con->idle); - kmscon_compositor_unref(con->comp); kmscon_console_unref(con->con); + kmscon_compositor_unref(con->comp); kmscon_vt_unref(con->vt); kmscon_eloop_rm_fd(con->stdin_fd); kmscon_eloop_rm_signal(con->sig_int); @@ -293,11 +293,11 @@ static int setup_eloop(struct console *con) if (ret) goto err_loop; - ret = kmscon_console_new(&con->con); + ret = kmscon_compositor_new(&con->comp); if (ret) goto err_loop; - ret = kmscon_compositor_new(&con->comp); + ret = kmscon_console_new(&con->con); if (ret) goto err_loop; @@ -327,6 +327,8 @@ int main(int argc, char **argv) return abs(ret); } + log_info("Starting console\n"); + schedule_draw(&con); while (!terminate) { @@ -335,6 +337,8 @@ int main(int argc, char **argv) break; } + log_info("Stopping console\n"); + destroy_eloop(&con); return abs(ret); }