I'm building an object in C using the most recent SDK, Max 6.1.2, OSX 10.8.3. It's based on the index~ example in the SDK.
I want to build a data structure based on an analysis of the samples in the referenced buffer~ object, but my object seems to crash when I do this at init time.
Here's the fragment I'm working with:
buffer = buffer_ref_getobject(x->l_buffer_reference);
tab = buffer_locksamples(buffer);
frames = buffer_getframecount(buffer);
post("frames: %ld", frames);
The several variables are declared.
If I place this code at the end of the set() function, it crashes. If I place it to execute only when a buffer~ is (re)set, things works fine. In set():
x->l_buffer_reference = buffer_ref_new((t_object*)x, s);
// Crashes if inserted here.
// Doesn't crash if inserted here.
I'm presuming this has something to do with my object's (or the buffer~'s) initialization, perhaps having not completed when buffer_ref_new() is called.
I also tried placing this code at the end of my object's new() routine, and it appears to crash there as well.
So, any thoughts on the judicious placement of code that wants to evaluate a buffer~ on init, and also anytime the buffer~ is reset?
Many thanks, Charles