From fa82bd927dd922d9b4d8f91d6983a970750a71bf Mon Sep 17 00:00:00 2001
From: Jonathan Wilkes <jon.w.wilkes@gmail.com>
Date: Mon, 25 Apr 2016 22:37:39 -0400
Subject: [PATCH] jwilkes/purr-data#49 check for non-existent image names from
 moonlib/image

---
 pd/nw/pdgui.js | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/pd/nw/pdgui.js b/pd/nw/pdgui.js
index 2a51befc4..e0f26df49 100644
--- a/pd/nw/pdgui.js
+++ b/pd/nw/pdgui.js
@@ -3015,11 +3015,16 @@ function gui_image_toggle_border(cid, tag, state) {
 // Switch the data for an existing svg image
 function gui_image_configure(cid, tag, image_key, tk_anchor) {
     var i = get_item(cid, tag);
-    i.setAttributeNS("http://www.w3.org/1999/xlink", "href",
-        "data:image/" + pd_cache.get(image_key).type + ";base64," +
-         pd_cache.get(image_key).data);
-    img_size_setter(cid, tag, pd_cache.get(image_key).type,
-        pd_cache.get(image_key).data, tk_anchor);
+    if (pd_cache.get(image_key)) {
+        i.setAttributeNS("http://www.w3.org/1999/xlink", "href",
+            "data:image/" + pd_cache.get(image_key).type + ";base64," +
+             pd_cache.get(image_key).data);
+        img_size_setter(cid, tag, pd_cache.get(image_key).type,
+            pd_cache.get(image_key).data, tk_anchor);
+    } else {
+        // need to change this to an actual error
+        post("image: error: can't find image");
+    }
 }
 
 // Move an image
-- 
GitLab