Code

Simple first pass for rough timing
[inkscape.git] / src / widgets / icon.cpp
index eed9d4b56510415b70a278ef052a84b137ea5d3e..d8d68461440cdd645711b0c514bbe62c62fa1476 100644 (file)
@@ -5,6 +5,7 @@
  * Author:
  *   Lauris Kaplinski <lauris@kaplinski.com>
  *   Jon A. Cruz <jon@joncruz.org>
+ *   Abhishek Sharma
  *
  * Copyright (C) 2002 Lauris Kaplinski
  *
@@ -19,6 +20,7 @@
 #include <glib/gmem.h>
 #include <gtk/gtk.h>
 #include <gtkmm.h>
+#include <gdkmm/pixbuf.h>
 
 #include "path-prefix.h"
 #include "preferences.h"
@@ -89,16 +91,12 @@ public:
     GdkPixbuf* _pb;
 };
 
-static Glib::RefPtr<Gtk::IconFactory> inkyIcons;
 static std::map<Glib::ustring, std::vector<IconCacheItem> > iconSetCache;
+static std::set<Glib::ustring> internalNames;
 
 GType
 sp_icon_get_type()
 {
-    //TODO: switch to GObject
-    // GtkType and such calls were deprecated a while back with the
-    // introduction of GObject as a separate layer, with GType instead. --JonCruz
-
     static GType type = 0;
     if (!type) {
         GTypeInfo info = {
@@ -223,7 +221,7 @@ void sp_icon_fetch_pixbuf( SPIcon *icon )
     }
 }
 
-static GdkPixbuf* renderup( gchar const* name, Inkscape::IconSize lsize, unsigned psize ) {
+GdkPixbuf* renderup( gchar const* name, Inkscape::IconSize lsize, unsigned psize ) {
     GtkIconTheme *theme = gtk_icon_theme_get_default();
 
     GdkPixbuf *pb = 0;
@@ -274,7 +272,10 @@ static void sp_icon_style_set( GtkWidget *widget, GtkStyle *previous_style )
 
 static void sp_icon_theme_changed( SPIcon *icon )
 {
-    //g_message("Got a change bump for this icon");
+    bool const dump = Inkscape::Preferences::get()->getBool("/debug/icons/dumpSvg");
+    if ( dump ) {
+        g_message("Got a change bump for this icon");
+    }
     sizeDirty = true;
     sp_icon_reset(icon);
     gtk_widget_queue_draw( GTK_WIDGET(icon) );
@@ -283,9 +284,8 @@ static void sp_icon_theme_changed( SPIcon *icon )
 
 static void imageMapCB(GtkWidget* widget, gpointer user_data);
 static void imageMapNamedCB(GtkWidget* widget, gpointer user_data);
-static void populate_placeholder_icon(gchar const* name, GtkIconSize size);
 static bool prerender_icon(gchar const *name, GtkIconSize lsize, unsigned psize);
-static Glib::ustring icon_cache_key(gchar const *name, unsigned lsize, unsigned psize);
+static Glib::ustring icon_cache_key(gchar const *name, unsigned psize);
 static GdkPixbuf *get_cached_pixbuf(Glib::ustring const &key);
 
 static void setupLegacyNaming() {
@@ -383,7 +383,7 @@ static void setupLegacyNaming() {
     legacyNames["text-unkern"] ="remove_manual_kerns";
     legacyNames["help-keyboard-shortcuts"] ="help_keys";
     legacyNames["help-contents"] ="help_tutorials";
-    legacyNames["inkscape"] ="inkscape_options";
+    legacyNames["inkscape-logo"] ="inkscape_options";
     legacyNames["dialog-memory"] ="about_memory";
     legacyNames["tool-pointer"] ="draw_select";
     legacyNames["tool-node-editor"] ="draw_node";
@@ -543,11 +543,9 @@ static void setupLegacyNaming() {
     legacyNames["zoom"] ="sticky_zoom";
 }
 
-static GtkWidget *
-sp_icon_new_full( Inkscape::IconSize lsize, gchar const *name )
+static GtkWidget *sp_icon_new_full( Inkscape::IconSize lsize, gchar const *name )
 {
-    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
-    static bool dump = prefs->getBool( "/debug/icons/dumpGtk");
+    static bool dump = Inkscape::Preferences::get()->getBool("/debug/icons/dumpGtk");
 
     GtkWidget *widget = 0;
     gint trySize = CLAMP( static_cast<gint>(lsize), 0, static_cast<gint>(G_N_ELEMENTS(iconSizeLookup) - 1) );
@@ -580,7 +578,6 @@ sp_icon_new_full( Inkscape::IconSize lsize, gchar const *name )
         if ( type == GTK_IMAGE_STOCK ) {
             if ( !stockFound ) {
                 // It's not showing as a stock ID, so assume it will be present internally
-                populate_placeholder_icon( name, mappedSize );
                 addPreRender( mappedSize, name );
 
                 // Add a hook to render if set visible before prerender is done.
@@ -598,16 +595,10 @@ sp_icon_new_full( Inkscape::IconSize lsize, gchar const *name )
             widget = GTK_WIDGET(img);
             img = 0;
 
-//             if (!gtk_icon_theme_has_icon(gtk_icon_theme_get_default(), name)) {
-//                 // TODO temporary work-around. until background rendering is restored.
-//                 int psize = sp_icon_get_phys_size(lsize);
-//                 renderup(name, lsize, psize);
-//             }
-
             // Add a hook to render if set visible before prerender is done.
             g_signal_connect( G_OBJECT(widget), "map", G_CALLBACK(imageMapNamedCB), GINT_TO_POINTER(0) );
 
-            if ( prefs->getBool("/options/iconrender/named_nodelay") ) {
+            if ( Inkscape::Preferences::get()->getBool("/options/iconrender/named_nodelay") ) {
                 int psize = sp_icon_get_phys_size(lsize);
                 prerender_icon(name, mappedSize, psize);
             } else {
@@ -679,8 +670,7 @@ static void injectCustomSize()
     // TODO - still need to handle the case of theme changes and resize, especially as we can't re-register a string.
     if ( !sizeMapDone )
     {
-        Inkscape::Preferences *prefs = Inkscape::Preferences::get();
-        bool dump = prefs->getBool( "/debug/icons/dumpDefault");
+        bool dump = Inkscape::Preferences::get()->getBool("/debug/icons/dumpDefault");
         gint width = 0;
         gint height = 0;
         if ( gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height ) ) {
@@ -701,13 +691,6 @@ static void injectCustomSize()
         }
         sizeMapDone = true;
     }
-
-    static bool hit = false;
-    if ( !hit ) {
-        hit = true;
-        inkyIcons = Gtk::IconFactory::create();
-        inkyIcons->add_default();
-    }
 }
 
 GtkIconSize Inkscape::getRegisteredIconSize( Inkscape::IconSize size )
@@ -732,7 +715,7 @@ int sp_icon_get_phys_size(int size)
     static int lastSys[Inkscape::ICON_SIZE_DECORATION + 1];
     static int vals[Inkscape::ICON_SIZE_DECORATION + 1];
 
-    size = CLAMP( size, GTK_ICON_SIZE_MENU, Inkscape::ICON_SIZE_DECORATION );
+    size = CLAMP( size, static_cast<int>(GTK_ICON_SIZE_MENU), static_cast<int>(Inkscape::ICON_SIZE_DECORATION) );
 
     if ( !sizeMapDone ) {
         injectCustomSize();
@@ -765,9 +748,7 @@ int sp_icon_get_phys_size(int size)
 
     if ( !init ) {
         sizeDirty = false;
-        Inkscape::Preferences *prefs = Inkscape::Preferences::get();
-        bool dump = prefs->getBool("/debug/icons/dumpDefault");
-
+        bool dump = Inkscape::Preferences::get()->getBool("/debug/icons/dumpDefault");
         if ( dump ) {
             g_message( "Default icon sizes:" );
         }
@@ -814,6 +795,11 @@ int sp_icon_get_phys_size(int size)
                           i, gtkSizes[i],
                           ( used ? ' ' : 'X' ), width, height, names[i]);
             }
+
+            // The following is needed due to this documented behavior of gtk_icon_size_lookup:
+            //   "The rendered pixbuf may not even correspond to the width/height returned by
+            //   gtk_icon_size_lookup(), because themes are free to render the pixbuf however
+            //   they like, including changing the usual size."
             gchar const *id = GTK_STOCK_OPEN;
             GdkPixbuf *pb = gtk_widget_render_icon( icon, id, gtkSizes[i], NULL);
             if (pb) {
@@ -835,15 +821,6 @@ int sp_icon_get_phys_size(int size)
         init = true;
     }
 
-    // Fixup workaround
-    if ((size == GTK_ICON_SIZE_MENU) || (size == GTK_ICON_SIZE_SMALL_TOOLBAR) || (size == GTK_ICON_SIZE_LARGE_TOOLBAR)) {
-        gint width = 0;
-        gint height = 0;
-        if ( gtk_icon_size_lookup( static_cast<GtkIconSize>(size), &width, &height ) ) {
-            vals[size] = std::max( width, height );
-        }
-    }
-
     return vals[size];
 }
 
@@ -935,21 +912,20 @@ extern "C" guchar *
 sp_icon_doc_icon( SPDocument *doc, NRArenaItem *root,
                   gchar const *name, unsigned psize )
 {
-    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
-    bool const dump = prefs->getBool("/debug/icons/dumpSvg");
+    bool const dump = Inkscape::Preferences::get()->getBool("/debug/icons/dumpSvg");
     guchar *px = NULL;
 
     if (doc) {
         SPObject *object = doc->getObjectById(name);
         if (object && SP_IS_ITEM(object)) {
             /* Find bbox in document */
-            Geom::Matrix const i2doc(sp_item_i2doc_affine(SP_ITEM(object)));
+            Geom::Matrix const i2doc(SP_ITEM(object)->i2doc_affine());
             Geom::OptRect dbox = SP_ITEM(object)->getBounds(i2doc);
 
             if ( SP_OBJECT_PARENT(object) == NULL )
             {
                 dbox = Geom::Rect(Geom::Point(0, 0),
-                                Geom::Point(sp_document_width(doc), sp_document_height(doc)));
+                                Geom::Point(doc->getWidth(), doc->getHeight()));
             }
 
             /* This is in document coordinates, i.e. pixels */
@@ -1049,8 +1025,7 @@ sp_icon_doc_icon( SPDocument *doc, NRArenaItem *root,
                                              NR_ARENA_ITEM_RENDER_NO_CACHE );
                 nr_pixblock_release(&B);
 
-                bool useOverlay = prefs->getBool("/debug/icons/overlaySvg");
-                if ( useOverlay ) {
+                if ( Inkscape::Preferences::get()->getBool("/debug/icons/overlaySvg") ) {
                     sp_icon_overlay_pixels( px, psize, psize, 4 * psize, 0x00, 0x00, 0xff );
                 }
             }
@@ -1071,23 +1046,21 @@ struct svg_doc_cache_t
 static std::map<Glib::ustring, svg_doc_cache_t *> doc_cache;
 static std::map<Glib::ustring, GdkPixbuf *> pb_cache;
 
-Glib::ustring icon_cache_key(gchar const *name,
-                             unsigned lsize, unsigned psize)
+Glib::ustring icon_cache_key(gchar const *name, unsigned psize)
 {
     Glib::ustring key=name;
     key += ":";
-    key += lsize;
-    key += ":";
     key += psize;
     return key;
 }
 
 GdkPixbuf *get_cached_pixbuf(Glib::ustring const &key) {
+    GdkPixbuf* pb = 0;
     std::map<Glib::ustring, GdkPixbuf *>::iterator found = pb_cache.find(key);
     if ( found != pb_cache.end() ) {
-        return found->second;
+        pb = found->second;
     }
-    return NULL;
+    return pb;
 }
 
 static std::list<gchar*> &icons_svg_paths()
@@ -1133,18 +1106,37 @@ static guchar *load_svg_pixels(gchar const *name,
         /* Try to load from document. */
         if (!info &&
             Inkscape::IO::file_test( doc_filename, G_FILE_TEST_IS_REGULAR ) &&
-            (doc = sp_document_new( doc_filename, FALSE )) ) {
+            (doc = SPDocument::createNewDoc( doc_filename, FALSE )) ) {
 
             //g_message("Loaded icon file %s", doc_filename);
             // prep the document
-            sp_document_ensure_up_to_date(doc);
+            doc->ensureUpToDate();
             /* Create new arena */
             NRArena *arena = NRArena::create();
             /* Create ArenaItem and set transform */
-            unsigned visionkey = sp_item_display_key_new(1);
+            unsigned visionkey = SPItem::display_key_new(1);
             /* fixme: Memory manage root if needed (Lauris) */
-            root = sp_item_invoke_show( SP_ITEM(SP_DOCUMENT_ROOT(doc)),
-                                        arena, visionkey, SP_ITEM_SHOW_DISPLAY );
+            // This needs to be fixed indeed; this leads to a memory leak of a few megabytes these days
+            // because shapes are being rendered which are not being freed
+            // Valgrind output:
+            /*==7014== 1,548,344 bytes in 599 blocks are possibly lost in loss record 20,361 of 20,362
+            ==7014==    at 0x4A05974: operator new(unsigned long) (vg_replace_malloc.c:220)
+            ==7014==    by 0x4F1015: __gnu_cxx::new_allocator<Shape::point_data>::allocate(unsigned long, void const*) (new_allocator.h:89)
+            ==7014==    by 0x4F02AC: std::_Vector_base<Shape::point_data, std::allocator<Shape::point_data> >::_M_allocate(unsigned long) (stl_vector.h:140)
+            ==7014==    by 0xCF62D7: std::vector<Shape::point_data, std::allocator<Shape::point_data> >::_M_fill_insert(__gnu_cxx::__normal_iterator<Shape::point_data*, std::vector<Shape::point_data, std::allocator<Shape::point_data> > >, unsigned long, Shape::point_data const&) (vector.tcc:414)
+            ==7014==    by 0xCF4D45: std::vector<Shape::point_data, std::allocator<Shape::point_data> >::insert(__gnu_cxx::__normal_iterator<Shape::point_data*, std::vector<Shape::point_data, std::allocator<Shape::point_data> > >, unsigned long, Shape::point_data const&) (stl_vector.h:851)
+            ==7014==    by 0xCF3DCD: std::vector<Shape::point_data, std::allocator<Shape::point_data> >::resize(unsigned long, Shape::point_data) (stl_vector.h:557)
+            ==7014==    by 0xCEA771: Shape::AddPoint(Geom::Point) (Shape.cpp:326)
+            ==7014==    by 0xD0F413: Shape::ConvertToShape(Shape*, fill_typ, bool) (ShapeSweep.cpp:257)
+            ==7014==    by 0x5ECD4F: nr_arena_shape_update_stroke(NRArenaShape*, NRGC*, NRRectL*) (nr-arena-shape.cpp:651)
+            ==7014==    by 0x5EE0DA: nr_arena_shape_render(_cairo*, NRArenaItem*, NRRectL*, NRPixBlock*, unsigned int) (nr-arena-shape.cpp:862)
+            ==7014==    by 0x5E72FB: nr_arena_item_invoke_render(_cairo*, NRArenaItem*, NRRectL const*, NRPixBlock*, unsigned int) (nr-arena-item.cpp:578)
+            ==7014==    by 0x5E9DDE: nr_arena_group_render(_cairo*, NRArenaItem*, NRRectL*, NRPixBlock*, unsigned int) (nr-arena-group.cpp:228)
+            ==7014==    by 0x5E72FB: nr_arena_item_invoke_render(_cairo*, NRArenaItem*, NRRectL const*, NRPixBlock*, unsigned int) (nr-arena-item.cpp:578)
+            ==7014==    by 0x5E9DDE: nr_arena_group_render(_cairo*, NRArenaItem*, NRRectL*, NRPixBlock*, unsigned int) (nr-arena-group.cpp:228)
+            ==7014==    by 0x5E72FB: nr_arena_item_invoke_render(_cairo*, NRArenaItem*, NRRectL const*, NRPixBlock*, unsigned int) (nr-arena-item.cpp:578)
+            */
+            root = SP_ITEM(doc->getRoot())->invoke_show(arena, visionkey, SP_ITEM_SHOW_DISPLAY );
 
             // store into the cache
             info = new svg_doc_cache_t;
@@ -1176,120 +1168,123 @@ static guchar *load_svg_pixels(gchar const *name,
     return px;
 }
 
-static void populate_placeholder_icon(gchar const* name, GtkIconSize size)
-{
-    if ( iconSetCache.find(name) == iconSetCache.end() ) {
-        // only add a placeholder if nothing is already set
-        Gtk::IconSet icnset;
-        Gtk::IconSource src;
-        src.set_icon_name( GTK_STOCK_MISSING_IMAGE );
-        src.set_size( Gtk::IconSize(size) );
-        icnset.add_source(src);
-        inkyIcons->add(Gtk::StockID(name), icnset);
-    }
-}
-
 static void addToIconSet(GdkPixbuf* pb, gchar const* name, GtkIconSize lsize, unsigned psize) {
-    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
-    static bool dump = prefs->getBool("/debug/icons/dumpGtk");
+    static bool dump = Inkscape::Preferences::get()->getBool("/debug/icons/dumpGtk");
     GtkStockItem stock;
     gboolean stockFound = gtk_stock_lookup( name, &stock );
-    if ( !stockFound ) {
+   if ( !stockFound ) {
         Gtk::IconTheme::add_builtin_icon( name, psize, Glib::wrap(pb) );
         if (dump) {
             g_message("    set in a builtin for %s:%d:%d", name, lsize, psize);
         }
     }
+}
 
-    for ( std::vector<IconCacheItem>::iterator it = iconSetCache[name].begin(); it != iconSetCache[name].end(); ++it ) {
-        if ( it->_lsize == lsize ) {
-            if (dump) {
-                g_message("         erasing %s:%d   %p", name, it->_lsize, it->_pb);
-            }
-            iconSetCache[name].erase(it);
-            break;
+void Inkscape::queueIconPrerender( Glib::ustring const &name, Inkscape::IconSize lsize )
+{
+    GtkStockItem stock;
+    gboolean stockFound = gtk_stock_lookup( name.c_str(), &stock );
+    gboolean themedFound = gtk_icon_theme_has_icon(gtk_icon_theme_get_default(), name.c_str());
+    if (!stockFound && !themedFound ) {
+        gint trySize = CLAMP( static_cast<gint>(lsize), 0, static_cast<gint>(G_N_ELEMENTS(iconSizeLookup) - 1) );
+        if ( !sizeMapDone ) {
+            injectCustomSize();
         }
+        GtkIconSize mappedSize = iconSizeLookup[trySize];
+
+        int psize = sp_icon_get_phys_size(lsize);
+        // TODO place in a queue that is triggered by other map events
+        prerender_icon(name.c_str(), mappedSize, psize);
     }
-    iconSetCache[name].push_back(IconCacheItem(lsize, pb));
-
-    Gtk::IconSet icnset;
-    for ( std::vector<IconCacheItem>::iterator it = iconSetCache[name].begin(); it != iconSetCache[name].end(); ++it ) {
-        Gtk::IconSource src;
-        g_object_ref( G_OBJECT(it->_pb) );
-        src.set_pixbuf( Glib::wrap(it->_pb) );
-        src.set_size( Gtk::IconSize(it->_lsize) );
-        src.set_size_wildcarded( (it->_lsize != 1) || (iconSetCache[name].size() == 1) );
-        src.set_state_wildcarded( true );
-        icnset.add_source(src);
-    }
-    inkyIcons->add(Gtk::StockID(name), icnset);
 }
 
 // returns true if icon needed preloading, false if nothing was done
 bool prerender_icon(gchar const *name, GtkIconSize lsize, unsigned psize)
 {
-    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
-    static bool dump = prefs->getBool("/debug/icons/dumpGtk");
-
-    Glib::ustring key = icon_cache_key(name, lsize, psize);
-    GdkPixbuf *pb = get_cached_pixbuf(key);
-    if (pb) {
-        return false;
-    } else {
-        GtkIconTheme* theme = gtk_icon_theme_get_default();
-        if ( gtk_icon_theme_has_icon(theme, name) ) {
-            gint *sizeArray = gtk_icon_theme_get_icon_sizes( theme, name );
-            for (gint* cur = sizeArray; *cur; cur++) {
-                if (static_cast<gint>(psize) == *cur) {
-                    pb = gtk_icon_theme_load_icon( theme, name, psize,
-                                                   (GtkIconLookupFlags) 0, NULL );
-                    break;
-                }
-            }
-            g_free(sizeArray);
-            sizeArray = 0;
-        }
-        if (!pb) {
+    bool loadNeeded = false;
+    static bool dump = Inkscape::Preferences::get()->getBool("/debug/icons/dumpGtk");
+    static bool useCache = Inkscape::Preferences::get()->getBool("/debug/icons/useCache");
+
+    Glib::ustring key = icon_cache_key(name, psize);
+    if ( !get_cached_pixbuf(key) ) {
+        if ((internalNames.find(name) != internalNames.end())
+            || (!gtk_icon_theme_has_icon(gtk_icon_theme_get_default(), name))) {
             if (dump) {
                 g_message("prerender_icon  [%s] %d:%d", name, lsize, psize);
             }
-            guchar* px = load_svg_pixels(name, lsize, psize);
-            if ( !px ) {
-                // check for a fallback name
-                if ( legacyNames.find(name) != legacyNames.end() ) {
-                    if ( dump ) {
-                        g_message("load_svg_pixels([%s]=%s, %d, %d)", name, legacyNames[name].c_str(), lsize, psize);
+            // In file encoding:
+            std::string iconCacheDir = Glib::build_filename(Glib::build_filename(Glib::get_user_cache_dir(), "inkscape"), "icons");
+            std::string potentialFile = Glib::build_filename( iconCacheDir, name );
+            potentialFile += ".png";
+            
+            bool dataLoaded = false;
+            if ( useCache && Glib::file_test(potentialFile, Glib::FILE_TEST_EXISTS) && Glib::file_test(potentialFile, Glib::FILE_TEST_IS_REGULAR) ) {
+                Glib::RefPtr<Gdk::Pixbuf> pb = Gdk::Pixbuf::create_from_file(potentialFile);
+                if (pb) {
+                    dataLoaded = true;
+                    GdkPixbuf *obj = pb->gobj();
+                    g_object_ref(obj);
+                    pb_cache[key] = obj;
+                    addToIconSet(obj, name, lsize, psize);
+                    loadNeeded = true;
+                    if (internalNames.find(name) == internalNames.end()) {
+                        internalNames.insert(name);
                     }
-                    px = load_svg_pixels(legacyNames[name].c_str(), lsize, psize);
                 }
             }
-            if (px) {
-                pb = gdk_pixbuf_new_from_data(px, GDK_COLORSPACE_RGB, TRUE, 8,
-                                              psize, psize, psize * 4,
-                                              (GdkPixbufDestroyNotify)g_free, NULL);
-            } else if (dump) {
-                g_message("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX  error!!! pixels not found for '%s'", name);
+
+            if (!dataLoaded) {
+                guchar* px = load_svg_pixels(name, lsize, psize);
+                if ( !px ) {
+                    // check for a fallback name
+                    if ( legacyNames.find(name) != legacyNames.end() ) {
+                        if ( dump ) {
+                            g_message("load_svg_pixels([%s]=%s, %d, %d)", name, legacyNames[name].c_str(), lsize, psize);
+                        }
+                        px = load_svg_pixels(legacyNames[name].c_str(), lsize, psize);
+                    }
+                }
+                if (px) {
+                    GdkPixbuf* pb = gdk_pixbuf_new_from_data( px, GDK_COLORSPACE_RGB, TRUE, 8,
+                                                              psize, psize, psize * 4,
+                                                              reinterpret_cast<GdkPixbufDestroyNotify>(g_free), NULL );
+                    pb_cache[key] = pb;
+                    addToIconSet(pb, name, lsize, psize);
+                    loadNeeded = true;
+                    if (internalNames.find(name) == internalNames.end()) {
+                        internalNames.insert(name);
+                    }
+                    if (useCache) {
+                        g_object_ref(pb);
+                        Glib::RefPtr<Gdk::Pixbuf> ppp = Glib::wrap(pb);
+                        try {
+                            ppp->save( potentialFile, "png" );
+                        } catch ( Glib::FileError &ex ) {
+                            g_warning("FileError    [%s]", ex.what().c_str());
+                        } catch ( Gdk::PixbufError &ex ) {
+                            g_warning("PixbufError  [%s]", ex.what().c_str());
+                        }
+                    }
+                } else if (dump) {
+                    g_message("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX  error!!! pixels not found for '%s'", name);
+                }
             }
         }
         else if (dump) {
             g_message("prerender_icon  [%s] %d NOT!!!!!!", name, psize);
         }
-
-        if (pb) {
-            pb_cache[key] = pb;
-            addToIconSet(pb, name, lsize, psize);
-        }
-        return true;
     }
+    return loadNeeded;
 }
 
 static GdkPixbuf *sp_icon_image_load_svg(gchar const *name, GtkIconSize lsize, unsigned psize)
 {
-    Glib::ustring key = icon_cache_key(name, lsize, psize);
+    Glib::ustring key = icon_cache_key(name, psize);
 
     // did we already load this icon at this scale/size?
     GdkPixbuf* pb = get_cached_pixbuf(key);
     if (!pb) {
+        g_message("YYYYYYYYYYYYY YYYYYYYYYYYYYYY two load_svg_pixels(%s, %d, %d)", name, lsize, psize);
         guchar *px = load_svg_pixels(name, lsize, psize);
         if (px) {
             pb = gdk_pixbuf_new_from_data(px, GDK_COLORSPACE_RGB, TRUE, 8,
@@ -1391,7 +1386,9 @@ static void addPreRender( GtkIconSize lsize, gchar const *name )
 }
 
 gboolean icon_prerender_task(gpointer /*data*/) {
-    if (!pendingRenders.empty()) {
+    if ( inkscapeIsCrashing() ) {
+        // stop
+    } else if (!pendingRenders.empty()) {
         bool workDone = false;
         do {
             preRenderItem single = pendingRenders.front();
@@ -1401,7 +1398,7 @@ gboolean icon_prerender_task(gpointer /*data*/) {
         } while (!pendingRenders.empty() && !workDone);
     }
 
-    if (!pendingRenders.empty()) {
+    if (!inkscapeIsCrashing() && !pendingRenders.empty()) {
         return TRUE;
     } else {
         callbackHooked = false;
@@ -1447,21 +1444,9 @@ static void imageMapNamedCB(GtkWidget* widget, gpointer user_data) {
             gint iconSize = 0;
             gchar* iconName = 0;
             {
-                GIcon* gicon = 0;
-                GtkIconSet* iconSet = 0;
-                GdkImage* iii = 0;
-                GdkPixbuf* pixbuf = 0;
-                gint pixelSize = 0;
-                gchar* stock = 0;
                 g_object_get(G_OBJECT(widget),
-                             "gicon", &gicon,
-                             "icon-set", &iconSet,
                              "icon-name", &iconName,
                              "icon-size", &iconSize,
-                             "image", &iii,
-                             "pixbuf", &pixbuf,
-                             "pixel-size", &pixelSize,
-                             "stock", &stock,
                              NULL);
             }
 
@@ -1494,4 +1479,4 @@ static void imageMapNamedCB(GtkWidget* widget, gpointer user_data) {
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :