danomatika / ofxPd

(maintained) a Pure Data addon for OpenFrameworks using libpd
Other
202 stars 45 forks source link

Crash while opening/closing the Pd patch on Mac OSX #60

Closed cuinjune closed 6 years ago

cuinjune commented 7 years ago

Hi, I found out ofxPd app crashes randomly while opening/closing Pd patches using pd.openPatch() and pd.closePatch() on Mac OSX.

Here's a simple example code you can test.

In ofApp.h

    ofxPd pd;
    Patch patch;
    bool isPatchOpened;
    int keyCount;

in ofApp.cpp

//--------------------------------------------------------------
void ofApp::setup() {

    ofSetFrameRate(60);
    ofSetVerticalSync(true);

    int ticksPerBuffer = 8;
    int numInputs = 1;

    ofSoundStreamSetup(2, numInputs, this, 44100, ofxPd::blockSize()*ticksPerBuffer, 3);

    if(!pd.init(2, numInputs, 44100, ticksPerBuffer, false)) {
        OF_EXIT_APP(1);
    }
    pd.addReceiver(*this);

    pd.start();

    isPatchOpened = false;
}

//--------------------------------------------------------------
void ofApp::update() {

    if (!isPatchOpened) {

        patch = pd.openPatch("pd/test.pd");
        isPatchOpened = true;
    }
    else {

        pd.closePatch(patch);
        isPatchOpened = false;
    }
    cout << "keyCount : " << ++keyCount << endl;

}

//--------------------------------------------------------------
void ofApp::draw() {

    ofSetColor(0, 255, 0);
    ofDrawRectangle(100, 100, 200, 200);

    if (isPatchOpened) {

        ofSetColor(255, 0, 0);
        ofDrawCircle(200, 200, 100);
    }
}

If you run the app, it will try to open and close a pd patch every frame. At some point, you will see the app crashing.

screen shot 2017-07-12 at 3 00 07 pm

Sometimes, it also crashes on resizeBytes() or sometimes it crashed on some method in ofUtils.cpp

screen shot 2017-07-12 at 3 30 23 pm

It seemed like the heavier patch I use, the earlier the crash occurred. So if you want to see the crash earlier, you can simply create [osc~] x 100 times on the empty patch and try with it.

I also tested this on iOS and Android but they both seemed to be working fine. So I'm guessing that it is a Mac OSX specific problem.

I used OF v0.9.8 on Mac OSX 10.11.6. I really hope it can be fixed.

Thank you.

Miles-Tone commented 7 years ago

heya! what mac have you tested this on? Im having problems with the newer MacBooks

cuinjune commented 7 years ago

@Miles-Tone Hi, I used MacBook Pro (Retina, Mid 2012)

Miles-Tone commented 7 years ago

Ah ok, so it seems like my issue and this one are similar, if not the same. It must be a problem for anything newer than the retina MacBooks, could it be an architecture issue. 32/64?

Miles-Tone commented 7 years ago

Have you tested it on an older mac?

danomatika commented 7 years ago

I found out ofxPd app crashes randomly while opening/closing Pd patches using pd.openPatch() and pd.closePatch() on Mac OSX.

Are you opening and closing patches every now and then or every update? I don't think you should expect to be able to constantly open/close patches 30-60 times a second as it takes a nominal amount of time to simply open and read a file...

cuinjune commented 7 years ago

Hey Dan. Thanks for your answer! My test code originally opens/closes a patch on key presses. And it crashed even when I slowly open and close the patch with key press events. It's just that the crash randomly occurred so I couldn't predict if it will crash on 100th or 1000th key press. That's why I moved opening/closing part to update() so that tester can quickly see the app crashing. And even if it opens/closes a patch 60 times a second, I think it should only slow down the app but not crash. I tested the same code on iOS and Android but it never crashed on these platforms but it certainly crashes on my Macbook Pro. I will also try this on Ubuntu and let you know if it crashes or not.

cuinjune commented 7 years ago

@Miles-Tone Hey Miles, No I haven't tested this on older Mac as this one is the only Mac I have now. ofxPd works fine on my Macbook Pro in general. It compiles and I can hear sound from Pd patch. I think you are having trouble with your newest Macbook Pro. Can you at least compile and run ofxPd/pdExample? Which OSX version do you use?

Miles-Tone commented 7 years ago

@cuinjune oh ok, thanks, sounds like something different is going on for me then, ill keep it in the other issue thread

cuinjune commented 7 years ago

I tried the test code on Ubuntu and it worked without the crash. So I'm pretty certain that it is Mac OS X specific problem.

micuat commented 6 years ago

@cuinjune I had similar issue while running pdExampleIOS on iPad 2. Since I deleted openPatch()'s except the very first one, the issue seems to be gone.

danomatika commented 6 years ago

Any updates on this? I just updated the libpd version.

danomatika commented 6 years ago

Closing due to inactivity.