From: Pawel Wasowski Date: Mon, 18 Jan 2021 13:01:19 +0000 (+0100) Subject: [ML][pipeline] Prepare room for a bugfix X-Git-Tag: submit/tizen/20210128.113801~25 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8eb1cc23dc863571f3519e4419283e2b1f423271;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [ML][pipeline] Prepare room for a bugfix Native handles to all pipeline elements (switches, node infos, etc.) have to be released BEFORE Pipeline::pipeline_ handle. Pipeline::Dispose() will release them in proper order and from now on will be called from ~Pipeline() to not repeat the error prone release logic. [Verification] Code tested with below snippets in Chrome DevTools works fine. var pipeline = tizen.ml.pipeline.createPipeline('videotestsrc ! tizenwlsink', function(state) {console.log(state);}) // test screen appears pipeline.dispose() // no errors, test screen disappear; // DLOG message about successful disposal // no crash; DLOG message tells that pipeline_ has been destroyed Change-Id: Ibe8b1260bc7bf057fed375ac579b87fce59d8caf Signed-off-by: Pawel Wasowski --- diff --git a/src/ml/ml_pipeline.cc b/src/ml/ml_pipeline.cc index 440d7734..63b6fbf7 100644 --- a/src/ml/ml_pipeline.cc +++ b/src/ml/ml_pipeline.cc @@ -117,11 +117,7 @@ Pipeline::~Pipeline() { return; } - auto ret = ml_pipeline_destroy(pipeline_); - if (ML_ERROR_NONE != ret) { - LoggerE("ml_pipeline_destroy() failed: [%d] (%s)", ret, get_error_message(ret)); - } - LoggerD("ml_pipeline_destroy() succeeded"); + Dispose(); } void Pipeline::PipelineStateChangeListener(ml_pipeline_state_e state, void* user_data) { @@ -166,6 +162,17 @@ PlatformResult Pipeline::GetState(std::string* out) { PlatformResult Pipeline::Dispose() { ScopeLogger("id_: [%d]", id_); + /* + * TODO in future commits: + * + * Release all nodes belonging to this pipeline and + * cached in this object in containers like + * switches_, node_infos_, etc. + * + * They have to be released HERE (i.e. BEFORE releasing pipeline_). + * If they're released after pipeline_, the app may crash. + */ + auto ret = ml_pipeline_destroy(pipeline_); if (ML_ERROR_NONE != ret) { LoggerE("ml_pipeline_destroy() failed: [%d] (%s)", ret, get_error_message(ret)); diff --git a/src/ml/ml_pipeline.h b/src/ml/ml_pipeline.h index 92e2fa93..5fd19aab 100644 --- a/src/ml/ml_pipeline.h +++ b/src/ml/ml_pipeline.h @@ -125,6 +125,11 @@ class Pipeline { private: Pipeline(int id, const std::string& state_change_listener_name, common::Instance* instance_ptr); + /* ######### VERY IMPORTANT ######### + * All nnstreamer handles to nodes belonging to this Pipeline + * object have to be released in Dispose(), before calling + * ml_pipeline_destroy(pipeline_) (otherwise, the app may crash). + */ const int id_; ml_pipeline_h pipeline_; const std::string state_change_listener_name_;