From 24cebbda5813450b0196253cc7c26aa773f23622 Mon Sep 17 00:00:00 2001 From: lethosor Date: Tue, 28 Apr 2020 21:38:47 -0400 Subject: [PATCH] Fix segfault when setting DFHACK_HEADLESS but not PRINT_MODE:TEXT endwin() is unhappy if initscr() wasn't called --- library/Core.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/library/Core.cpp b/library/Core.cpp index c0a1155c7..a9fe9a69a 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -1692,14 +1692,21 @@ bool Core::Init() if (is_headless) { #ifdef LINUX_BUILD - auto endwin = (int(*)(void))dlsym(RTLD_DEFAULT, "endwin"); - if (endwin) + if (is_text_mode) { - endwin(); + auto endwin = (int(*)(void))dlsym(RTLD_DEFAULT, "endwin"); + if (endwin) + { + endwin(); + } + else + { + cerr << "endwin(): bind failed" << endl; + } } else { - cerr << "endwin(): bind failed" << endl; + cerr << "Headless mode requires PRINT_MODE:TEXT" << endl; } #else cerr << "Headless mode not supported on Windows" << endl;