gazebosim / gazebosim/gz-rendering

Ownership questions

Open
#13 2 comments 0 reactions 0 assignees View on GitHub
enhancement proposal
Dominant language
C++
Stars
81
Forks
90
Avg merge
1d 13h
Merged PRs (30d)
10

Description

**Original report ([archived issue](https://osrf-migration.github.io/ignition-gh-pages/#!/ignitionrobotics/ign-rendering/issues/13)) by Louise Poubel (Bitbucket: [chapulina](https://bitbucket.org/%7B5cfa2075-477b-4ded-bdb9-8d2479544ec4%7D/), GitHub: [chapulina](https://github.com/chapulina)).**

----------------------------------------
I noticed on the examples that it is common to use `Scene::Create*` functions to instantiate most of the rendering types, as opposed to directly calling the type's constructor. All `Create*` functions return shared pointers.

1. Does the scene keep shared ownership of everything which is created by `Scene::Create*`?

```
This seems to be true for some types but not others, for example:
```

```
auto light = scene->CreateDirectionalLight();
ASSERT_EQ(light.use_count(), 2u); // passes
```

```
auto ray = scene->CreateRayQuery();
ASSERT_EQ(ray.use_count(), 1u); // passes
```

I'd suggest we return `unique_ptr`s for those which the scene won't be keeping1. When calling `Visual::AddChild`, is the ownership shared with the visual? The same goes for other `Add` and `Set` functions which take `shared_ptr`s

1. What's the appropriate way to destroy something which was created with `Scene::Create*`? There are some `Scene::Destroy*` functions, but there isn't a 1-1 relation to the creates. How to destroy the missing ones?

1. Is there a situation when an object should / could be instantiated without the use of `Scene::Create*`?

Contributor guide

Open the contributing guide

Research direction

Start by tracing the ownership behavior of the Scene::Create* and Scene::Destroy* functions, then inspect Visual::AddChild and the other Add/Set methods that accept shared pointers. Compare those paths with the light and ray-query examples; done requires an agreed, documented ownership and destruction policy before any API changes can be scoped.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
computer-graphics
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.