Knearest issue

I would like to report some problems with knearest.
First of all, I get one and sometimes both of the following errors when the delay of computation decreases, but at the same time, it seems to do the job.
I will appreciate some clarifications about that:

ERROR: FluidKDTree - Invalid buffer
ERROR: FluidKDTree - Wrong Point Size

Then, I tried to update FluCoMa Beta7 for SC, but knearest returns only NIL, see examples in documentation FluidKDTree.
Y.

Sorry you’re having problems. For the Buffer error messages, I suspect it’s an ordering issue: if you can share a snippet that reproduces the problem, I’ll try and figure out what’s going on.

For the beta 7 thing – it looks like the help file examples all need updating to reflect that kNearest's signature has changed: you can now pass k as a second optional argument, but that means action needs to be passed as a named argument if k is missing. i.e.

This has actually already been updated int the help files – my local build was stale :face_with_open_eyes_and_hand_over_mouth:

So, I’m not sure what problem you’re experiencing with beta 7. Are you saying that going through the help file and executing the blocks is always giving you nil in kNearest? One way to help debug is to see what’s coming back from the server…

So, you could put an OSC trace before calling kNearest:

//Return the labels of k nearest points to a new point
(
        ~p = [ 1.0.linrand,1.0.linrand ];
        OSCFunc.trace(true,true); 
        ~tmpbuf = Buffer.loadCollection(s, ~p, 1, {
            ~tree.kNearest(~tmpbuf, action:{ |a|a.postln;~nearest = a;})
        });
)

and you should be able to see what messages the server is sending back:

OSC Message Received:
	time: 4335.683998949
	address: a NetAddr(127.0.0.1, 57110)
	recvPort: 57120
	msg: [ /b_info, 1, 2, 1, 44100.0 ]

OSC Message Received:
	time: 4335.684622008
	address: a NetAddr(127.0.0.1, 57110)
	recvPort: 57120
	msg: [ /done, /b_allocRead, 1 ]

[ 5, 84, 95, 4, 68, 66, 61, 81, 62, 25, 51 ]
OSC Message Received:
	time: 4335.707135644
	address: a NetAddr(127.0.0.1, 57110)
	recvPort: 57120
	msg: [ /FluidKDTree/kNearest, 1, 5, 84, 95, 4, 68, 66, 61, 81, 62, 25, 51 ]

Ok. The issue on beta 7 is when you evaluate this in the example of help browser:

(
~p = [ 1.0.linrand,1.0.linrand ];
~tmpbuf = Buffer.loadCollection(s, ~p, 1, {
    ~tree.kNearest(~tmpbuf,{ |a| a.postln; ~nearest = a;})
});
)

it does not post anything and ~nearest stay NIL. When you add action: it works.
In both cases, the result is written in the buffer ~tmpbuf.

~tmpbuf.getn(0, 2, {|x| x.postln})

I am working on my code to figure out what’s going on, thanks for the tip. be back soon…

Right, that is the old help file code!

Two possibilities,

  • either we messed up deployment and didn’t ship the updated code (which I’m about to check),
  • or you need to recompile your class library (cmd shift L) and possibly reindex your help files (SCDoc.indexAllDocuments(true))

Yes, we messed up. The help file in the beta7 zip isn’t updated. So, to fix that problem temporarily, change kNearest call to

    ~tree.kNearest(~tmpbuf, action:{ |a| a.postln; ~nearest = a;})

I am going briefly to summarize my coding.
I made a function to compute the id of knearest and retrieve data via dataset in order to set a Synth.
So far so good.
Then inside an OSCDef when I call this function everything is fine.
Now the idea is to play a routine triggered by the OSC message.

if(msg[1].asInteger == 1)
{
	Routine.new(
		{
			~array_of_durations.do
			{
				arg i;
				~processNearest.(~dataIn); 
				i.wait;
			}
		}
	).play
}

That’s where it gets complicated.
For short delay times I get one or more of these messages:

File '/Users/yannics/Library/Application Support/SuperCollider/tmp/1099054756' could not be opened: System error : No such file or directory.
ERROR: FluidKDTree - Invalid buffer
ERROR: FluidKDTree - Wrong Point Size
FAILURE IN SERVER /b_getn index out of range

Note that it works fine when I test the function “by hand”, even for a short delay between triggers.
if it can help, here are some traces of incoming OSC messages:

... 

OSC Message Received:
	time: 9067.076143511
	address: a NetAddr(127.0.0.1, 57110)
	recvPort: 57120
	msg: [ /b_info, 0, 7, 1, 44100.0 ]

OSC Message Received:
	time: 9067.076898069
	address: a NetAddr(127.0.0.1, 57110)
	recvPort: 57120
	msg: [ /done, /b_allocRead, 0 ]

File '/Users/yannics/Library/Application Support/SuperCollider/tmp/-755816904' could not be opened: System error : No such file or directory.
OSC Message Received:
	time: 9067.077232717
	address: a NetAddr(127.0.0.1, 57110)
	recvPort: 57120
	msg: [ /fail, /b_allocRead, File '/Users/yannics/Library/Application Support/SuperCollider/tmp/-755816904' could not be opened: System error : No such file or directory.
, 0 ]

ERROR: FluidKDTree - Invalid buffer
OSC Message Received:
	time: 9067.083886444
	address: a NetAddr(127.0.0.1, 57110)
	recvPort: 57120
	msg: [ /done, /b_free, 0 ]

...

OSC Message Received:
	time: 9070.075430399
	address: a NetAddr(127.0.0.1, 57110)
	recvPort: 57120
	msg: [ /b_info, 0, 7, 1, 44100.0 ]

OSC Message Received:
	time: 9070.075750689
	address: a NetAddr(127.0.0.1, 57110)
	recvPort: 57120
	msg: [ /done, /b_allocRead, 0 ]

ERROR: FluidKDTree - Wrong Point Size
OSC Message Received:
	time: 9070.092449748
	address: a NetAddr(127.0.0.1, 57110)
	recvPort: 57120
	msg: [ /b_info, 0, 10, 1, 44100.0 ]

OSC Message Received:
	time: 9070.092672072
	address: a NetAddr(127.0.0.1, 57110)
	recvPort: 57120
	msg: [ /FluidDataSet/getPoint, 0 ]

...

Forget my last message.
I messed up my code.
The issue is about incoming messages during the routine.
I have to change my strategy.
Sorry about that.
:grin:

1 Like

No worries – glad you found the problem!