From 18026c363df3a0be9513f57ea95195e290f9be26 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Wed, 16 Jul 2014 15:26:14 -0700 Subject: [PATCH] No need to initialize map value to 0 (bug fix) There's no need to initialize the map value to 0. What was happening is that obs_scene_add was adding a ref to a non-existent value, which simply created it and added 1, which is perfectly fine. Then, obs_add_source would set the ref to 0, overwriting the existing value. So this meant that if you didn't call them in the right order, it wouldn't work properly, and would break, which was pretty stupid. Turns out that if you access a map value that doesn't exist, it'll create one with the default constructor of that type. In this case, int will initialize to 0, which was exactly what we wanted in the first place, and defeats the purpose of even needing to initialize the value to 0. So, there's no need to manually set it to 0 in OBSBasic::SourceAdded, or worry about the order in which the functions are called. Just goes to show you have to be careful with reference counting. --- obs/window-basic-main.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/obs/window-basic-main.cpp b/obs/window-basic-main.cpp index aba109543..5dc1f0cf4 100644 --- a/obs/window-basic-main.cpp +++ b/obs/window-basic-main.cpp @@ -993,8 +993,6 @@ void OBSBasic::SourceAdded(void *data, calldata_t params) QMetaObject::invokeMethod(window, "AddScene", Q_ARG(OBSSource, OBSSource(source))); - else - window->sourceSceneRefs[source] = 0; } void OBSBasic::SourceRemoved(void *data, calldata_t params)