tinyzimmer / go-gst

Gstreamer bindings and utilities for golang
GNU Lesser General Public License v2.1
130 stars 37 forks source link

pipeline.Unref() -> GLib-GObject-CRITICAL #62

Closed devbrom closed 1 year ago

devbrom commented 1 year ago

At the first, thanks for very useful GStreamer binding for golang.

In my case, I must create and delete gst pipelines in runtime. According to the GStreamer documentation, I must call gst_object_unref for unnecessary pipelines for freeing resources.

When I call pipeline.Unref(), I get following error: GLib-GObject-CRITICAL **: 11:54:51.773: g_object_unref: assertion 'G_IS_OBJECT (object)' failed

Do you have any ideas how it can be resolved?

Thanks

brucekim commented 1 year ago

You don't need to call Unref explicitly in go-gst because go-glib implements to do it when finalizing it's resource.

Refer to the following code snippet for your understanding.

https://github.com/tinyzimmer/go-gst/blob/439704fa4bd7417c27920d464467a3e5b289cb8f/gst/gst_pipeline.go#L21C2-L21C2

// FromGstPipelineUnsafeFull wraps the given pipeline pointer.
func FromGstPipelineUnsafeFull(pipeline unsafe.Pointer) *Pipeline {
    return &Pipeline{Bin: &Bin{&Element{wrapObject(glib.TransferFull(pipeline))}}}
}

https://github.com/tinyzimmer/go-glib/blob/bbba84fa5112edee5ffec776800883a3f9e5fc9f/glib/gobject.go#L87C1-L94C2

// TransferFull wraps a unsafe.Pointer as a glib.Object, taking ownership of it.
// it does not increase the ref count on the object. A finalizer is placed on the object
// to clear the transfered ref.
func TransferFull(ptr unsafe.Pointer) *Object {
    obj := newObject(ToGObject(ptr))
    runtime.SetFinalizer(obj, (*Object).Unref)
    return obj
}

BRs, bruc2kim

RSWilli commented 1 year ago

@devbrom move this issue to https://github.com/go-gst/go-gst (where future development of the bindings will take place) if you think it is necessary.

Although in short: No don't call Unref() it is done for you when the variable goes out of scope (via a finalizer). The bindings are aiming for a more golang like development experience.

devbrom commented 1 year ago

OK, understood. Thanks for your answers. Issue is closed.