I wanted to make a suggestion as a result of a bug I spent a good deal of time tracking down: Have Event::operator() make a copy of d_slots and iterate over that to notify subscribers. That way subscribers are free to modify the list of subscribers (e.g. remove themselves) without causing a runtime exception to be thrown; instead, the event notification will go on its merry way notifying the subscribers that were subscribed at the time that the event occurred.
It is often very convenient for a subscriber to be able to remove itself or another subscriber. For example, I have a message box with a cancel button; when the cancel button gets pressed, the creator of the message box destroys the message box (resets its shared pointer to the message box), which in turn disconnects the cancel button subscriber. (I reuse the message box Window, instead of reloading it every time since it takes a noticeable amount of time to load). It would also be convenient because I and others would not run into this bug anymore (which might decrease forum traffic slightly too ).
Use copy of event subscribers list during event notification
Moderators: CEGUI MVP, CEGUI Team
Re: Use copy of event subscribers list during event notification
I had a similar problem with another SDK I was using. I think that your approach would work, but would scale poorly. To avoid the unnecessary copy overhead, we could instead change the unsubscribe method to populate a queue (ptr to subscriber), and have operator() remove subscribers in this queue prior to iterating. This way only relevant subscribers are touched. I believe CEGUI already does something like this for window destruction.
If somebody helps you by replying to your thread, upvote him/her as a thanks! Make sure to include your CEGUI.log and everything you tried when posting! And remember that we are not magicians!
Return to “Bug Reports, Suggestions, Feature Requests”
Who is online
Users browsing this forum: No registered users and 5 guests