"this" is null in Closure
Submitted by Christopher Vollick
Link to original bug (#731482)
Description
In my understanding, this code should work:
protected delegate void WithoutSelf();
class ... {
protected void later(ClockTime time, WithoutSelf run) {
Gst.Clock.id_wait_async(SystemClock.obtain().new_single_shot_id(time),
(clock,time,id) => {
run();
return true;
});
}
public void play_later(ClockTime time) {
this.later(time, () => {
this.state = State.PLAYING;
});
}
}
But instead we get assertions saying that "this" is null. We've instead implemented the following, which operates as expected:
protected delegate void WithSelf(VideoPlayer self);
class ... {
protected void later(ClockTime time, WithSelf run) {
Gst.Clock.id_wait_async(SystemClock.obtain().new_single_shot_id(time),
(clock,time,id) => {
run(this);
return true;
});
}
public void play_later(ClockTime time) {
this.later(time, (self) => {
self.state = State.PLAYING;
});
}
}
Version: 0.24.x
Edited by Rico Tzschichholz