Working with a buffer~ object at init time?
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
Also, when I use the function buffer_ref_getexists(), I get the following linker error:
Undefined symbols for architecture x86_64:
"_buffer_ref_getexists", referenced from:
_stationary_set in stationary~.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
(I’m not savvy enough with Xcode to know why it’s telling me about x86_64 when my project is set to 32-bit.)
Looks like the MaxAudioAPI has the function called _buffer_ref_exists(), and a change to the ext_buffer.h declaration will get Xcode to compile my object successfully. It does however crash when I try to run it.
In the index~ example, the variable "tab" is used to check if the buffer~ can be used (if the function returns NULL you shouldn’t try to read it), look at the perform function in the example. Perhaps, you should use the defer_low() to call your reading method to be sure that the buffer~ has been well referenced in your structure.
Grossly, architecture x86_64 is for 32-bit(x86) and 64-bit processor.
Both excellent suggestions; problem solved.
Thanks for helping me out of my crash-induced blindness!
Best wishes, Charles
Forums > Dev