summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/preferences.cpp23
-rw-r--r--src/preferences.h9
2 files changed, 17 insertions, 15 deletions
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
diff --git a/src/preferences.h b/src/preferences.h
index d977fd73c..50133f584 100644
--- a/src/preferences.h
+++ b/src/preferences.h
@@ -641,10 +641,11 @@ private:
std::string _prefs_filename; ///< Full filename (with directory) of the prefs file
Glib::ustring _lastErrPrimary; ///< Last primary error message, if any.
Glib::ustring _lastErrSecondary; ///< Last secondary error message, if any.
- XML::Document *_prefs_doc; ///< XML document storing all the preferences
- ErrorReporter* _errorHandler; ///< Pointer to object reporting errors.
- bool _writable; ///< Will the preferences be saved at exit?
- bool _hasError; ///< Indication that some error has occurred;
+ XML::Document *_prefs_doc = nullptr; ///< XML document storing all the preferences
+ ErrorReporter *_errorHandler = nullptr; ///< Pointer to object reporting errors.
+ bool _writable = false; ///< Will the preferences be saved at exit?
+ bool _hasError = false; ///< Indication that some error has occurred;
+ bool _initialized = false; ///< Is this instance fully initialized? Caching should be avoided before.
std::unordered_map<std::string, Glib::ustring> cachedRawValue;
/// Wrapper class for XML node observers