From 4e391f5eb1990bb9c7004721a2f21fa93b012681 Mon Sep 17 00:00:00 2001
From: Jonathan Wilkes <jon.w.wilkes@gmail.com>
Date: Thu, 12 Jan 2017 12:05:32 -0500
Subject: [PATCH] bugfix for out-of-order messages arriving to
 gui_configure_grid

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

diff --git a/pd/nw/pdgui.js b/pd/nw/pdgui.js
index a2b952f37..6792b491f 100644
--- a/pd/nw/pdgui.js
+++ b/pd/nw/pdgui.js
@@ -3615,10 +3615,18 @@ function get_grid_data(w, h, x_l, y_l) {
 }
 
 function gui_configure_grid(cid, tag, w, h, bg_color, has_grid, x_l, y_l) {
-    var g = get_gobj(cid, tag),
-    // configure each element in the grid
+    var g,
         grid_d_string,
         point_size = 5;
+    // Quick bugfix for messages that arrive to the GUI before the
+    // window is mapped. This can happen when the user connects
+    // [loadbang] to a [grid] method that changes visual display (like "color")
+    // We need a way to prevent sending such messages
+    if (!patchwin[cid]) {
+        return;
+    }
+    g = get_gobj(cid, tag);
+    // configure each element in the grid
     configure_item(g.querySelector(".bg"), {
         width: w,
         height: h,
-- 
GitLab