Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buffer and Bus validity checks and Errors #2936

Merged
merged 1 commit into from
Jun 16, 2017

Conversation

patrickdupuis
Copy link
Contributor

Fixes #2851 (and see discussion #2846)

Some methods need to check that a Buffer/Bus is still valid before doing anything potentially destructive. The Server interprets 'nil' as zero in received messages. This means that Buffer and Bus index:0 are at risk of being modified when some methods are called on previously freed Buffers/Busses.

Hopefully, this solution is acceptable. Please review and critique away! :)

@jamshark70
Copy link
Contributor

I'd prefer to catch direct use of the *Msg methods as well -- currently this helps only for object-style usage (which will catch most cases, but it's not truly complete).

And I just found this -- EventTypesWithCleanup bypasses the Buffer methods altogether. Setting control buses by events may be similar.

s.boot;

a = Buffer.alloc(s, 128, 1, completionMessage: { |buf| buf.sine1Msg([1]) });
b = Buffer.alloc(s, 128, 1);
b.setn(0, Signal.fill(128, { 1.0.rand2 }));

b.free;

(type: \sine1, bufNum: b, amps: [1, 1]).play;

a.plot  // a is affected even though the event said bufNum: b

@patrickdupuis
Copy link
Contributor Author

I know that this solution isn't ideal. At one point, I has though about checking validity only inside the *Msg methods. That way, we aren't checking .isNil twice if we call for example .set (which then calls setMsg).

Looking at this again, I noticed some inconsistencies with how some methods and their respective *Msg methods are implemented. Compare Buffer set/setMsg to gen/ genMsg. In the case of gen, both methods send a potentially destructive server message!

@nhthn nhthn added the comp: class library SC class library label Jun 11, 2017
@@ -370,6 +371,7 @@ Buffer {
}

zero { arg completionMessage;
if(bufnum.isNil) { Error("Cannot call % on a % that has been freed".format(thisMethod.name, this.class.name)).throw };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could simplify these. just define one method:

checkForSend {
    if(bufnum.isNil) { Error("Cannot call % on a % that has been freed".format(thisMethod.name, this.class.name)).throw };
}

and then you just add the this.checkForSend everywhere.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine as-is

@telephon
Copy link
Member

The main reason why the implementation is so redundant is speed: argument passing is (relatively) slow, compared to method calls etc. And because these methods here are potential bottlenecks, they have these duplicates, like fill vs. fillMsg.

I've suggested a simplification which doesn't pass arguments. I think you could add this to the msg variants as well.

@telephon telephon merged commit 35f85a9 into supercollider:master Jun 16, 2017
@mossheim
Copy link
Contributor

@patrickdupuis, you are working on an alternate version or extension of this right?

@patrickdupuis
Copy link
Contributor Author

Yes - as we discussed yesterday, I was going to improve upon this. Can we un-merge?

Maybe, for now, I could simply add the same check to all the Msg type methods, and I'll commit myself to fixing it better for the next release.

@telephon
Copy link
Member

I'm sorry that I had misunderstood it. Can you be so kind and just make a new pull request on top? We just continue from there.

@patrickdupuis
Copy link
Contributor Author

no worries! I should have asked someone to label the PR as "Work in progess".

So, I can still add to this if I push to the same branch in my fork? That's good.

@telephon
Copy link
Member

telephon commented Jun 16, 2017

before you do more, can you try and push a little change to the same branch, and then see if github lets you make a pull request for it?

@mossheim
Copy link
Contributor

yeah, I would recommend pushing to the same branch

@mossheim
Copy link
Contributor

you won't be able to build on this PR, you will have to make a new one. since we have a no-force-push master, we can't undo it without also adding a revert commit. saves time just to add more on top of it.

@patrickdupuis patrickdupuis mentioned this pull request Jun 16, 2017
@patrickdupuis
Copy link
Contributor Author

patrickdupuis commented Jun 16, 2017

See #2959. I can create a new PR from this branch. Please merge this PR as soon as possible so that I can commit more changes to my branch 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp: class library SC class library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants