From 4b3c7e47a59de36107045475ec9a7d08b6238025 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 10 Jun 2016 16:34:36 +0100 Subject: [PATCH] Added ref_ptr<> usage to address memory leaks --- src/osgPlugins/osgjs/WriteVisitor | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/osgPlugins/osgjs/WriteVisitor b/src/osgPlugins/osgjs/WriteVisitor index 4f62155d1..c1e885e49 100644 --- a/src/osgPlugins/osgjs/WriteVisitor +++ b/src/osgPlugins/osgjs/WriteVisitor @@ -211,24 +211,24 @@ public: } void applyCallback(osg::Node& node, JSONObject* json) { - JSONArray* updateCallbacks = new JSONArray; - osg::Callback* nc = node.getUpdateCallback(); + osg::ref_ptr updateCallbacks = new JSONArray; + osg::ref_ptr nc = node.getUpdateCallback(); while (nc) { - osgAnimation::BasicAnimationManager* am = dynamic_cast(nc); + osgAnimation::BasicAnimationManager* am = dynamic_cast(nc.get()); if (am) { - JSONArray* array = new JSONArray; - JSONObject* bam = new JSONObject; + osg::ref_ptr array = new JSONArray; + osg::ref_ptr bam = new JSONObject; bam->getMaps()["Animations"] = array; - JSONObject* nodeCallbackObject = new JSONObject; + osg::ref_ptr nodeCallbackObject = new JSONObject; nodeCallbackObject->getMaps()["osgAnimation.BasicAnimationManager"] = bam; updateCallbacks->getArray().push_back(nodeCallbackObject); for ( unsigned int i = 0; i < am->getAnimationList().size(); i++) { osg::ref_ptr jsonAnim = createJSONAnimation(am->getAnimationList()[i].get()); if (jsonAnim) { - JSONObject* obj = new JSONObject; + osg::ref_ptr obj = new JSONObject; obj->getMaps()["osgAnimation.Animation"] = jsonAnim; array->getArray().push_back(obj); //std::stringstream ss; @@ -237,7 +237,7 @@ public: } } } else { - osgAnimation::UpdateMatrixTransform* updateMT = dynamic_cast(nc); + osgAnimation::UpdateMatrixTransform* updateMT = dynamic_cast(nc.get()); if (updateMT) { osg::ref_ptr jsonCallback = createJSONUpdateMatrixTransform(*updateMT); if (jsonCallback.valid()) {