ofxMaxim - occasional runtime errors


I started implementing the examples of Leon Fedden’s ofxMaxim tutorial series in oF 0.9.3. The code for the first two examples is in my ofxMaxim-examples repository.

In both examples I’m getting occasional runtime errors like this: Thread 1: EXC_BAD_ACCESS (code=EXC_i386_GPFLT) or Thread 1: EXC_BAD_INSTRUCTION (code=EXC_i386_INVOP, subcode 0x0). In almost all cases these errors occur in the ofAppGLFWWindow::update() method when this line is executed: glfwShowWindow(windowP);.

Since both errors seem to relate to the access of released objects, I’m assuming I’m doing something fundamentally wrong. On the other hand, these errors do not occur every time, though pretty often, when I run the examples, which makes me think this could also be either a bug in the addon or a bug related to my system – I’m running Mac OS X 10.10.5 on a Mid2010 MacBook Pro.

Any ideas how to fix this?


Hello @dcb,
The signature of the audioOut method looks strange. Also you are not calling ofxMaxiSettings::setup.
Change your ofApp.h like this

#pragma once
#include "ofMain.h"
#include "ofxMaxim.h"

class ofApp : public ofBaseApp{
    maxiOsc m_oscillator;
    double m_frequency;
    float m_amplitude;
    float m_current_sample;
    unsigned int m_sample_rate;
    unsigned int m_buffer_size;
    double  outputs[2];

    void setup();
    void update();
    void draw();
    void exit();
    // Audio output method
    void audioOut(float * output, int bufferSize, int nChannels);
    void mouseMoved(int x, int y );

And your App.cpp like this

#include "ofApp.h"
void ofApp::setup() {
    // set initial oscillator frequency to 440Hz
    m_frequency = 440;
    // set initial amplitude
    m_amplitude = 0.5f;
    // set audio sample rate to standard high resolution: 44.1kHz => 44100 samples per second
    m_sample_rate = 44100;
    // set number of samples per buffer
    m_buffer_size = 512;
    // this was missing, but it is needed
    ofxMaxiSettings::setup(m_sample_rate, 2, m_buffer_size);
    ofSetWindowTitle("A Simple Oscillator");
    // sets up and starts a global ofSoundStream.
    ofSoundStreamSetup(2, 0, m_sample_rate, m_buffer_size, 4);

void ofApp::update() {

void ofApp::draw() {

void ofApp::exit() {
    // stops the global sound stream and also cleans up the stream's resources

void ofApp::audioOut(float * output, int bufferSize, int nChannels) {
    for (int i = 0; i < bufferSize; i++){
        double wave = m_oscillator.square(m_frequency);
        output[i*nChannels    ] = wave;
        output[i*nChannels + 1] = wave;

void ofApp::mouseMoved(int x, int y ) {
    // update oscillator frequency based on mouse x-position
    m_frequency = (double) ofMap(x, 0, ofGetWidth(), 110, 880);
    // update sample amplitude based on mouse y-position
    m_amplitude = ofMap(y, 0, ofGetHeight(), 1.f, 0.f);   

I’ve pushed some usage examples of ofMaxim with of 0.9.3 at this repo https://github.com/edap/examplesOfxMaxim in case you are interested.

Hi @edapx,

thank you for your feedback. I did not know about the ofxMaxiSettings class. Digging into the source code of maximilian.h I found that the default buffer size is set to 1024 instead of 512.

The bigger issue though was the audioOut() method. Following the suggestions in the oF code, all audioOut() and audioRequested() are marked deprecated except for audioOut(ofSoundBuffer& buffer). See ofBaseTypes.h.

Nevertheless, changing the method’s signature back to audioOut(float * output, int bufferSize, int nChannels) fixed the issues I was experiencing. Calling ofxMaxiSettings::setup() did not make any difference, but I just follow your recommendation to call it.

And thanks for pointing me to your examples. Especially filters are of interest to me. Ultimately I’d like to work with Granular Synthesis. Do you have any experience with ofxMaxim in that regard?

Thanks again.

Hey @dcb, no, I’ve no experience with granular synthesis but I’ve seen that there is an example in the Maximilian repository. Did you already tried it ? https://github.com/micknoise/Maximilian/tree/master/openFrameworks/openFrameworksExamples/OSX/OF0.9.2_OSX_Granular0_92

Hey @edapx, just tested it, but there’s no playback. Sure it’ll be easy to fix. But that’s beyond the scope of this
thread. :wink: I also found this example, which will probably prove helpful: Live Audio Granular Synthesis with ofxMaxim.