Jypeli-JYU / Jypeli

A simple educational C# game programming library built on top of Silk.NET.
24 stars 4 forks source link

Fix input listener leaks in Widgets #15

Closed Anttifer closed 4 years ago

Anttifer commented 4 years ago

Fixed the rest of the listener leaks in Widgets. No functionality has been changed.

Noticed that Widget already had an unused internal member List named 'associatedListeners'. It is now used for keeping track of listeners to be removed.

It is worth noting that associatedListeners is still internal, so if a user decides to inherit Widget and associate listeners to it, they will have to take care of the cleanup themselves. On the other hand, though, they will not be able to mess up the default functionality of the Widgets either.

roeyskoe commented 4 years ago

Amazing :)

Maybe associatedListeners could be protected, so in case of inheriting users would not need to redo the listener removal?

But anyways, I'll publish a new nuget.

Anttifer commented 4 years ago

associatedListeners could certainly be protected, but this would expose the listeners added by the inherited widget to the user, who would then need to take care to preserve them if they decide to manipulate the list further and not just add listeners to it.

A better solution could be to introduce another automatically cleared list and expose it to users, but even this is probably unnecessary – if a user is savvy enough to create their own widgets, they're most likely capable of cleaning up after themselves.

However, in the documentation, it would make sense to insist on the responsibility of the user to remove any listeners they create.