diff --git a/fluid/Fluid_Image.cxx b/fluid/Fluid_Image.cxx index 69a75f8b8..342fec690 100644 --- a/fluid/Fluid_Image.cxx +++ b/fluid/Fluid_Image.cxx @@ -246,7 +246,18 @@ Fluid_Image* Fluid_Image::find(const char *iname) { } Fluid_Image::Fluid_Image(const char *iname) { - name_ = fl_strdup(iname); + size_t l = strlen(iname); + if (iname[0] != '/' && (strcmp(iname + l - 4, ".svg") == 0 || strcmp(iname + l - 5, ".svgz") == 0)) { + // When iname is the relative path of a .svg or .svgz file, + // put the full path in name_ because that file will be reopened later + // after the current directory has been changed by leave_source_dir(). + name_ = (const char *)malloc(FL_PATH_MAX + l + 2); + fl_getcwd((char*)name_, FL_PATH_MAX); + strcat((char*)name_, "/"); + strcat((char*)name_, iname); + } else { + name_ = fl_strdup(iname); + } written = 0; refcount = 0; img = Fl_Shared_Image::get(iname);