Skip to content
Snippets Groups Projects
  • Jim's avatar
    18026c36
    No need to initialize map value to 0 (bug fix) · 18026c36
    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.
    18026c36
    History
    No need to initialize map value to 0 (bug fix)
    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.