Working with a buffer~ object at init time?

May 22, 2013 at 8:40am

Working with a buffer~ object at init time?

Greetings-

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);
buffer_unlocksamples(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():

if (!x->l_buffer_reference)
x->l_buffer_reference = buffer_ref_new((t_object*)x, s);
// Crashes if inserted here.
else
buffer_ref_set(x->l_buffer_reference, s);
// 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

#250265
May 22, 2013 at 9:31am

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.

#250271
May 23, 2013 at 1:05am

Hi,

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.

Cheers

 

#250386
May 23, 2013 at 4:33am

Both excellent suggestions; problem solved.

Thanks for helping me out of my crash-induced blindness!

Best wishes, Charles

 

#250412

You must be logged in to reply to this topic.