From 2d7fa2d78f9af94b72472bb8e323f7a137136fa0 Mon Sep 17 00:00:00 2001
From: user <user@user-ThinkPad-X60.(none)>
Date: Sat, 2 May 2015 00:36:58 -0400
Subject: [PATCH] fixed bug when configuring xlets which don't exist (e.g.,
 autopatching and broken objects loaded with connections to others)

---
 pd/nw/pdgui.js | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/pd/nw/pdgui.js b/pd/nw/pdgui.js
index c14d57b91..50ba06506 100644
--- a/pd/nw/pdgui.js
+++ b/pd/nw/pdgui.js
@@ -1956,23 +1956,25 @@ function gui_eraseio(cid, tag) {
 
 function gui_configure_io(cid, tag, is_iemgui, is_signal, width) {
     var xlet = get_item(cid, tag);
-    configure_item(xlet, {
-        'stroke-width': width,
-//        fill: 'red'
-//        fill: filter ? 'orange' : (is_signal ? 'red' : 'green')
-    });
-    if (is_iemgui) {
-        xlet.classList.add('xlet_iemgui');
-    } else if (is_signal) {
-        xlet.classList.add('xlet_signal');
-    } else {
-        xlet.classList.add('xlet_control');
+    // We have to check for null here. Empty/broken object boxes
+    // can have "phantom" xlets as placeholders for connections
+    // to other objects. This may happen due to:
+    //   * autopatching
+    //   * objects which fail to create when loading a patch
+    if (xlet !== null) { 
+        configure_item(xlet, {
+            'stroke-width': width,
+        });
+        if (is_iemgui) {
+            xlet.classList.add('xlet_iemgui');
+        } else if (is_signal) {
+            xlet.classList.add('xlet_signal');
+        } else {
+            xlet.classList.add('xlet_control');
+        }
+        // remove xlet_selected tag
+        xlet.classList.remove('xlet_selected');
     }
-    // remove xlet_selected tag
-    xlet.classList.remove('xlet_selected');
-    // iemgui: black
-    // sig: red
-    // control: green
 }
 
 function gui_highlight_io(cid, tag) {
-- 
GitLab