From 251948bdbd5c4987eab68be5b6b023045f427296 Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 16 Jun 2016 03:05:45 +0000 Subject: [PATCH] GTK: don't crash if argv[0]=="solvespace". --- src/platform/gtkmain.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/platform/gtkmain.cpp b/src/platform/gtkmain.cpp index 3d1f9ef6..6937193b 100644 --- a/src/platform/gtkmain.cpp +++ b/src/platform/gtkmain.cpp @@ -1505,6 +1505,7 @@ const void *LoadResource(const std::string &name, size_t *size) { path = (UNIX_DATADIR "/") + name; if(stat(path.c_str(), &st)) { ssassert(errno == ENOENT, "Unexpected stat() error"); + ssassert(!resource_dir.empty(), "Expected local resource directory to be set"); path = resource_dir + "/" + name; ssassert(!stat(path.c_str(), &st), "Cannot find resource"); } @@ -1585,10 +1586,13 @@ int main(int argc, char** argv) { ambiguous. */ gtk_disable_setlocale(); - resource_dir = argv[0]; // .../src/solvespace - resource_dir.erase(resource_dir.rfind('/')); - resource_dir.erase(resource_dir.rfind('/')); - resource_dir += "/res"; // .../res + /* Are we running from a build directory, as opposed to a global install? */ + if(std::string(argv[0]).find('/') != std::string::npos) { + resource_dir = argv[0]; // .../src/solvespace + resource_dir.erase(resource_dir.rfind('/')); + resource_dir.erase(resource_dir.rfind('/')); + resource_dir += "/res"; // .../res + } Gtk::Main main(argc, argv);