Skip to content

Commit db8f904

Browse files
authored
Merge pull request #1 from MengLi619/fix-restart
fix: stop source can't close input stream
2 parents f892a82 + 722a760 commit db8f904

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/cpp/source.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Source::Source(std::string &id, SourceType type, std::string &url, obs_scene_t *
2929
obs_scene(obs_scene),
3030
settings(settings),
3131
obs_source(nullptr),
32+
obs_scene_item(nullptr),
3233
started(false) {
3334
}
3435

@@ -55,7 +56,7 @@ void Source::start() {
5556
}
5657

5758
// Add the source to the scene
58-
obs_sceneitem_t *obs_scene_item = obs_scene_add(obs_scene, obs_source);
59+
obs_scene_item = obs_scene_add(obs_scene, obs_source);
5960
if (!obs_scene_item) {
6061
throw std::runtime_error("Failed to add scene item.");
6162
}
@@ -72,8 +73,12 @@ void Source::start() {
7273
}
7374

7475
void Source::stop() {
76+
// Call obs_sceneitem_remove but not obs_sceneitem_release to avoid a segfault
77+
obs_sceneitem_remove(obs_scene_item);
7578
obs_source_remove(obs_source);
7679
obs_source_release(obs_source);
80+
obs_source = nullptr;
81+
obs_scene_item = nullptr;
7782
this->started = false;
7883
}
7984

src/cpp/source.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ class Source {
3131
obs_scene_t *obs_scene;
3232
Settings *settings;
3333
obs_source_t *obs_source;
34+
obs_scene_item *obs_scene_item;
3435
bool started;
3536
};

0 commit comments

Comments
 (0)