-
Jim authored
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.
Jim authoredThere'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.