arturoc / ofxTween

tween addon for openFrameworks
Other
80 stars 51 forks source link

Added copy constructor to ofxTween to handle ofxTween's dynamic allocations during copy. #10

Closed mitchmindtree closed 10 years ago

mitchmindtree commented 10 years ago

Hey @arturoc / @obviousjim, thanks for the awesome addon!

Just thought I'd send a pull request for this as it has helped make the implementation of ofxTween in my own project much smoother.

All i've added is a copy constructor which handles the dynamic allocations when copying ofxTween objects or copying classes that contain ofxTweens (or placing classes with an ofxTween that exist on the stack into a vector). Previously, during the member-wise copy in the implicit copy constructor the address at easingFunction would be copied across - if the previous tween's destructor was called directly after it would free the memory at it's easingFunction and thus also at the copy's easingFunction. The copy constructor simply makes sure each copy creates their own version of the easingFunction rather than just copying the address. In the case that it is NULL, it makes sure that the copy's is also NULL.

Let me know if there was already a way around this, otherwise I hope it can help someone the same way it's helped me!

Cheers

arturoc commented 10 years ago

thanks!