GTK: don't crash if argv[0]=="solvespace".

pull/19/head
whitequark 2016-06-16 03:05:45 +00:00
parent a98cdeeb16
commit 251948bdbd
1 changed files with 8 additions and 4 deletions

View File

@ -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();
/* 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);