From fe3c6f825131da03e278442d046565e4caaebb77 Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Sun, 20 Oct 2019 20:19:04 +0200 Subject: Preferences: hold-off on caching until fully instantiated This avoids caching "wrong" values when setting defaults in Preferences::_loadDefaults(). (we did this since 7ca9dc4c53873955a31c1b71559da9f7b29b4a2e for OS-specific defaults) Fixes https://gitlab.com/inkscape/inkscape/issues/99 --- src/preferences.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'src/preferences.cpp') diff --git a/src/preferences.cpp b/src/preferences.cpp index 72a570ca2..cd4e0e461 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -66,12 +66,7 @@ private: Glib::ustring const _filter; }; -Preferences::Preferences() : - _prefs_filename(""), - _prefs_doc(nullptr), - _errorHandler(nullptr), - _writable(false), - _hasError(false) +Preferences::Preferences() { char *path = Inkscape::IO::Resource::profile_path(PREFERENCES_FILE_NAME); _prefs_filename = path; @@ -79,6 +74,8 @@ Preferences::Preferences() : _loadDefaults(); _load(); + + _initialized = true; } Preferences::~Preferences() @@ -720,7 +717,8 @@ void Preferences::_getRawValue(Glib::ustring const &path, gchar const *&result) // will return empty string if `path` was not in the cache yet auto& cacheref = cachedRawValue[path.c_str()]; - if (!cacheref.empty()) { + // check in cache first + if (_initialized && !cacheref.empty()) { if (cacheref == RAWCACHE_CODE_NULL) { result = nullptr; } else { @@ -746,11 +744,11 @@ void Preferences::_getRawValue(Glib::ustring const &path, gchar const *&result) } } - if (!result) { - cacheref = RAWCACHE_CODE_NULL; - } else { + if (_initialized && result) { cacheref = RAWCACHE_CODE_VALUE; cacheref += result; + } else { + cacheref = RAWCACHE_CODE_NULL; } } @@ -763,7 +761,10 @@ void Preferences::_setRawValue(Glib::ustring const &path, Glib::ustring const &v // set the attribute Inkscape::XML::Node *node = _getNode(node_key, true); node->setAttribute(attr_key.c_str(), value.c_str()); - cachedRawValue[path.c_str()] = RAWCACHE_CODE_VALUE + value; + + if (_initialized) { + cachedRawValue[path.c_str()] = RAWCACHE_CODE_VALUE + value; + } } // The _extract* methods are where the actual work is done - they define how preferences are stored -- cgit v1.2.3