diff --git a/pd/src/g_editor.c b/pd/src/g_editor.c
index 38d6ddf15f71c2cba9c3443e0aedcdaa5a2c6da3..f3c746bb18bc7b89212325579e7928f2c1bf3593 100644
--- a/pd/src/g_editor.c
+++ b/pd/src/g_editor.c
@@ -5478,7 +5478,7 @@ void canvas_key(t_canvas *x, t_symbol *s, int ac, t_atom *av)
     // now broadcast key press to key et al. objects
     // ico@vt.edu 20200918: only do so if we do not have an object
     // that has grabbed the keyboard, such as gatom or iemgui numbox
-    if (!x->gl_editor->e_keyfn)
+    if (!x || !x->gl_editor || !x->gl_editor->e_keyfn)
     {
         if (!autorepeat)
         {