Skip to content

Commit 7d2f03f

Browse files
committed
Fix potential crash
1 parent 76439e8 commit 7d2f03f

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

Libraries/pure-data

Source/Pd/Instance.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,13 +334,19 @@ void Instance::initialisePd(String& pdlua_version)
334334
// Register callback for special Pd messages
335335
auto gui_trigger = [](void* instance, char const* name, int const argc, t_atom* argv) {
336336
switch (hash(name)) {
337+
// NOTE: this sometimes gets called when an object does sys_vgui("destroy %s") on something other than a canvas
338+
// don't dereference the glist until we're sure it's a canvas
337339
case hash("canvas_vis"): {
338340
auto* inst = static_cast<Instance*>(instance);
339341
if (inst->initialiseIntoPluginmode)
340342
return;
341343

342344
t_canvas* glist = reinterpret_cast<struct _glist*>(argv->a_w.w_gpointer);
343-
if(!glist->gl_owner) break;
345+
346+
// Make sure we're not a toplevel without checking gl_owner
347+
for (auto* x = pd_getcanvaslist(); x; x = x->gl_next)
348+
if(x == glist)
349+
return;
344350

345351
if (atom_getfloat(argv + 1)) {
346352
File patchFile;

0 commit comments

Comments
 (0)