Closed roddc closed 2 months ago
I don't see what is wrong. So I wouldn't know how to fix it. Maybe @rayman has a clue, to fix this.
this.rosTopic.subscribe(this.processMessage.bind(this));
this.rosTopic.unsubscribe(this.processMessage);
You need to unsubscribe with the exact same function. bind
creates a new function so this doesn't work
@rayman Thanks! This is done in many places in the library. So this is broken in all those places.
Would it be fixed by changing the unsubscribe
to this.rosTopic.unsubscribe(this.processMessage.bind(this));
? Or does every call to bind
create a new function that doesn't the old reference?
bind creates a new function, so that doesn't work. I'm thinking how to solve this, but it has been a few years since I've programmed in javascript.
bind creates a new function, so that doesn't work. I'm thinking how to solve this, but it has been a few years since I've programmed in javascript.
There're few solutions:
this.boundProcessMessage = this.processMessage.bind(this);
in the class constrcutor, and use it in the subscribe and unsubscribe functions.this.callback = (msg) => this.processMessage(msg)
.Hope it can help.
This has already been done in other parts of the lib, this should be extend to the entire lib. https://github.com/RobotWebTools/ros3djs/blob/c474671126631134c296d2cd486655b360326c37/src/interactivemarkers/InteractiveMarkerHandle.js#L44
This problem seems like fixed in https://github.com/RobotWebTools/ros3djs/pull/635 Thanks @MatthijsBurgh!
Description The PointCloud2 class cannot unsubscribe from the topic, because the reference of the callback is not the same as the one subscribed, and Roslib.Topic will not be unsubscribed if there's any other listeners.
Steps To Reproduce
I think this bug may appear in other classes like LaserScan.
Expected Behavior The topic should be unsubscribed.
Actual Behavior The
unsubscribe
function of PointCloud2 is not removing the correct callback.