Quesiton of obs_scene_find_source

AlexGuo1998

New Member
Hello devs.
Looking into the implementation of obs_scene_find_source (here), I noticed that the reference of returned sceneitem is not incremented.
Is it possible that the sceneitem gets destroyed before the scene gets released? e.g. User removes that item from the scene using GUI.
Should I call obs_sceneitem_addref manually?
BTW, I'm using obs_frontend_get_scenes to get that scene list.
Thanks!
 

Lain

Forum Admin
Lain
Forum Moderator
Developer
Yea, I think for that particular function it was a mistake to not increment the reference on my part. There are some functions which purposely don't increment (because the functions predicate on the caller already have an reference), but for this function I feel it was a mistake.

For now, I'd say if your code is not in the main thread, increment the reference from the return value to be safe, it's extremely unlikely (though admittedly not impossible) that it'll be destroyed in that time it's returned to the time you increment. Most of the time these functions are called, they're called from the main thread, and because the main thread typically is the holder of the frontend object references it's unlikely they'd be destroyed elsewhere, but if your code is not in the main thread then it's not impossible. Apologies for the trouble with that one. Race conditions can slip in anywhere if you're not careful, as that function shows. I should probably write newer versions of those functions (i.e. "obs_scene_find_source2") and deprecate the older versions.
 
Top