Weird CRASH caused by use of _sym-type symbols in an external on Max 9
On Max 9.0.5 running on a MacBook M1 Air laptop, I just observed a very strange reproducible crash, which can be demonstrated in the minimal external code below.
Note that in the jw_bang
method there are 4 illustrative cases which were tested individually and in each case where a _sym
-type symbol was used instead of a gensym
-type symbol it crashed. I will include the CMakeLists.txt
file at the end as well.
#include "ext.h"
#include "ext_obex.h"
#include "commonsyms.h"
typedef struct _jw
{
t_object ob; // the object itself (must be first)
void* outlet; // one outlet
} t_jw;
void* jw_new(void);
void jw_free(t_jw* x);
void jw_assist(t_jw* x, void* b, long m, long a, char* s);
void jw_bang(t_jw* x);
void* jw_class;
void ext_main(void* r)
{
t_class* c;
c = class_new("jw", (method)jw_new, (method)jw_free, (long)sizeof(t_jw),
0L /* leave NULL!! */, A_NOTHING, 0);
class_addmethod(c, (method)jw_bang, "bang", 0);
class_register(CLASS_BOX, c);
jw_class = c;
}
void jw_free(t_jw* x)
{
;
}
void* jw_new(void)
{
t_jw* x = NULL;
if ((x = (t_jw*)object_alloc(jw_class))) {
x->outlet = outlet_new(x, NULL);
}
return (x);
}
void jw_bang(t_jw* x)
{
// NO CRASH
t_object* mytable = (t_object*)object_new(gensym("nobox"), gensym("table"));
object_free(mytable);
// CRASH
t_object* mytable = (t_object*)object_new(_sym_nobox, _sym_table);
object_free(mytable);
// NO CRASH
t_object* jsonwriter = (t_object*)object_new(gensym("nobox"), gensym("jsonwriter"));
object_free(jsonwriter);
// CRASH
t_object* jsonwriter = (t_object*)object_new(_sym_nobox, _sym_jsonwriter);
object_free(jsonwriter);
outlet_bang(x->outlet);
}
Here is the CMakeLists.txt
file used:
include(${CMAKE_CURRENT_SOURCE_DIR}/../../max-sdk-base/script/max-pretarget.cmake)
include_directories(
"${MAX_SDK_INCLUDES}"
"${MAX_SDK_MSP_INCLUDES}"
"${MAX_SDK_JIT_INCLUDES}"
)
file(GLOB PROJECT_SRC
"*.h"
"*.c"
"*.cpp"
)
add_library(
${PROJECT_NAME}
MODULE
${PROJECT_SRC}
"${MAX_SDK_INCLUDES}/common/commonsyms.c"
)
include(${CMAKE_CURRENT_SOURCE_DIR}/../../max-sdk-base/script/max-posttarget.cmake)
@11OLSEN, thanks very much for clearing that mystery up.
I’m pretty sure that someone else will be bitten at some point!
S
Suggest to include the ‘common_symbols_init()’ requirement in the SDK docs.