From ff571fabcfe967b503358689359398678571d4d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Tue, 24 Jun 2014 11:39:16 +0200 Subject: [PATCH] fix exit crash due to forced loop stop --- src/map/map.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/map/map.cpp b/src/map/map.cpp index a77e9d0c5..294dca4b8 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -76,13 +76,6 @@ void Map::stop() { uv_thread_join(&thread); - uv_close((uv_handle_t *)async_terminate, delete_async); - async_terminate = nullptr; - uv_close((uv_handle_t *)async_render, delete_async); - async_render = nullptr; - uv_close((uv_handle_t *)async_cleanup, delete_async); - async_cleanup = nullptr; - // Run the event loop once to make sure our async delete handlers are called. uv_run(**loop, UV_RUN_ONCE); @@ -161,7 +154,13 @@ void Map::render(uv_async_t *async) { } void Map::terminate(uv_async_t *async) { - uv_stop(static_cast(async->data)); + // Closes all open handles on the loop. This means that the loop will automatically terminate. + uv_loop_t *loop = static_cast(async->data); + uv_walk(loop, [](uv_handle_t *handle, void *arg) { + if (!uv_is_closing(handle)) { + uv_close(handle, NULL); + } + }, NULL); } #pragma mark - Setup