diff options
| -rw-r--r-- | src/document.cpp | 8 | ||||
| -rw-r--r-- | src/document.h | 1 | ||||
| -rw-r--r-- | src/file.cpp | 8 |
3 files changed, 10 insertions, 7 deletions
diff --git a/src/document.cpp b/src/document.cpp index a2d7a32cb..3daae3deb 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -102,6 +102,7 @@ SPDocument::SPDocument() : root(nullptr), style_cascade(cr_cascade_new(nullptr, nullptr, nullptr)), style_sheet(nullptr), + ref_count(0), uri(nullptr), base(nullptr), name(nullptr), @@ -594,12 +595,19 @@ SPDocument *SPDocument::createNewDocFromMem(gchar const *buffer, gint length, un SPDocument *SPDocument::doRef() { + ++ref_count; + // std::cout << "SPDocument::doRef() " << ref_count << " " << this << std::endl; Inkscape::GC::anchor(this); return this; } SPDocument *SPDocument::doUnref() { + --ref_count; + if (ref_count < 0) { + std::cerr << "SPDocument::doUnref(): invalid ref count! " << ref_count << std::endl; + } + // std::cout << "SPDocument::doUnref() " << ref_count << " " << this << std::endl; Inkscape::GC::release(this); return nullptr; } diff --git a/src/document.h b/src/document.h index 6c14d5198..e22542f80 100644 --- a/src/document.h +++ b/src/document.h @@ -269,6 +269,7 @@ public: char const *base, char const *name, unsigned int keepalive, SPDocument *parent); + int ref_count; SPDocument *doRef(); SPDocument *doUnref(); Inkscape::Util::Unit const* getDisplayUnit() const; diff --git a/src/file.cpp b/src/file.cpp index 9e57c0658..255ed467b 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -146,8 +146,6 @@ SPDesktop *sp_file_new(const std::string &templ) sp_create_window(dtw, TRUE); SPDesktop* desktop = static_cast<SPDesktop *>(dtw->view); - doc->doUnref(); - sp_namedview_window_from_document(desktop); sp_namedview_update_layers_from_document(desktop); @@ -230,12 +228,12 @@ bool sp_file_open(const Glib::ustring &uri, doc = nullptr; cancelled = true; } + if (desktop) { desktop->clearWaitingCursor(); } if (doc) { - SPDocument *existing = desktop ? desktop->getDocument() : nullptr; if (existing && existing->virgin && replace_empty) { @@ -252,9 +250,6 @@ bool sp_file_open(const Glib::ustring &uri, doc->virgin = FALSE; - // everyone who cares now has a reference, get rid of our`s - doc->doUnref(); - SPRoot *root = doc->getRoot(); // This is the only place original values should be set. @@ -1299,7 +1294,6 @@ file_import(SPDocument *in_doc, const Glib::ustring &uri, } } - doc->doUnref(); DocumentUndo::done(in_doc, SP_VERB_FILE_IMPORT, _("Import")); return new_obj; |
