You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Clarify undefined behavior when target == source in PMatrix::mult docs #1591
I know this won't be top priority, but this issue caused me to spin my wheels for a couple days straight since it was one of those times where all my logic "looked right" after many passes so I figured it might throw some other beginners for a loop.
I'd like to request additional clarity be added to the javadoc here:
* Multiply source by this matrix, and return the result.
* The result will be stored in target if target is non-null, and target
* will then be the matrix returned. This improves performance if you reuse
* target, so it's recommended if you call this many times in draw().
*/
publicPVectormult(PVectorsource, PVectortarget);
Specifically, I think that it should be stated explicitly that behavior is undefined when target == source. Since no warning was offered I did not expect for the contents of source to still be in the process of being read by the time that target is actually being populated within this method but it appears something like that is happening (my expectation was that the contents of source would have probably been extracted into local variables once at the beginning since there are so few elements in a PVector and then loaded into target once at the end after performing intermediate computations). Ideally, if there is no utility in allowing target == source whatsoever, this case should throw an exception but, alternatively, additional doc clarity would have been a noninvasive way of preventing prolonged confusion in my case. Also I think "target will then be the matrix returned" is a typo since this method is returning a PVector.
Here is an example sketch you can use to observe the undocumented undefined behavior. Move the mouse around without pressing anything to observe normal behavior when simply passing target = null. Similarly, pressing Right-click will set target equal to a PVector reference which is fixed across draw() frames--the outcome of which is normal behavior. Pressing Left-click will pass target = source triggering the undefined behavior.
Activity