void gf_sg_del(GF_SceneGraph *sg)
{
	if (!sg) return;

#ifndef GPAC_DISABLE_VRML
	if (sg->global_qp) {
		gf_node_unregister(sg->global_qp, NULL);
		sg->global_qp = NULL;
	}
#endif

	gf_sg_reset(sg);

#ifndef GPAC_DISABLE_SVG

	gf_dom_event_target_del(sg->dom_evt);
	gf_list_del(sg->xlink_hrefs);
	gf_list_del(sg->smil_timed_elements);
	gf_list_del(sg->modified_smil_timed_elements);
	gf_list_del(sg->listeners_to_add);
	gf_mx_del(sg->dom_evt_mx);
#endif

#ifdef GPAC_HAS_QJS
	gf_list_del(sg->scripts);
	sg->scripts = NULL;
	gf_list_del(sg->objects);
	sg->objects = NULL;
#ifndef GPAC_DISABLE_SVG
	if (sg->svg_js) {
		void gf_svg_script_context_del(void *svg_js, GF_SceneGraph *scenegraph);
		gf_svg_script_context_del(sg->svg_js, sg);
	}
#endif

#endif //GPAC_HAS_QJS

#ifndef GPAC_DISABLE_VRML
	gf_list_del(sg->Routes);
	gf_list_del(sg->protos);
	gf_list_del(sg->unregistered_protos);
	gf_list_del(sg->routes_to_activate);
	gf_list_del(sg->routes_to_destroy);
#endif
	gf_list_del(sg->exported_nodes);
	gf_free(sg);
}
void gf_sg_del(GF_SceneGraph *sg)
{
	if (!sg) return;

#ifndef GPAC_DISABLE_VRML
	if (sg->global_qp) {
		gf_node_unregister(sg->global_qp, NULL);
		sg->global_qp = NULL;
	}
#endif

	gf_sg_reset(sg);

#ifndef GPAC_DISABLE_SVG

	gf_dom_event_target_del(sg->dom_evt);
	gf_list_del(sg->xlink_hrefs);
	gf_list_del(sg->smil_timed_elements);
	gf_list_del(sg->modified_smil_timed_elements);
	gf_list_del(sg->listeners_to_add);
	gf_mx_del(sg->dom_evt_mx);
#endif

#ifdef GPAC_HAS_QJS
	gf_list_del(sg->scripts);
	sg->scripts = NULL;
	gf_list_del(sg->objects);
	sg->objects = NULL;
#ifndef GPAC_DISABLE_SVG
	if (sg->svg_js) {
		void gf_svg_script_context_del(void *svg_js, GF_SceneGraph *scenegraph);
		gf_svg_script_context_del(sg->svg_js, sg);
	}
#endif

#endif  

#ifndef GPAC_DISABLE_VRML
	gf_list_del(sg->Routes);
	gf_list_del(sg->protos);
	gf_list_del(sg->unregistered_protos);
	gf_list_del(sg->routes_to_activate);
	gf_list_del(sg->routes_to_destroy);
#endif
	gf_list_del(sg->exported_nodes);
	gf_free(sg);
}