diff --git a/pd/nw/pdgui.js b/pd/nw/pdgui.js
index a2b952f372de680bb4cfb5f754c2a6532dfee6f0..6792b491fae7cfaf3de0e1af5931454749aba617 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,