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
I am creating a gallery of p5 images with many p5 instances on the same web page, several of which use p5.brush. Each instance dutifully calls brush.instance(sketch) in the sketch function it passes to the p5 constructor, and then calls brush.load() in its setup() method. However, I get one or more occurrences of RangeError: invalid array length when I load the page; it's occurring in genField() inside of _ensureReady(). More specifically, this.num_columns ends up as NaN.
What seems to be happening is that one p5 instance A is registering its blend methods (in the _registerMethods() function), and then before those methods get called by A, another instance B has called brush.instance(B) but that instance B has not yet called setup(), and then when blend() is called by the registered methods of A, the global variables _r and _inst are now pointing to B, which has no width property yet, and so the number of columns is being computed to be NaN.
In other words, it seems as though p5.brush is not actually designed to handle multiple p5 instances that are setting up asynchronously, because there is only one _r and one _inst variable in the module. Is that right, or is p5.brush supposed to work in this circumstance (and either I am doing something wrong or there still remains some bug in p5.brush handling multiple instances)?
If p5.brush is currently not designed to handle multiple p5 sketch instances, are you interested in extending p5.brush so that it is safe to use with multiple instances of p5 all running asynchronously? Presumably this would entail keeping multiple p5 instance references around, say in some collection of objects, and making sure that the proper instance is used in any given brush function (rather that just referring to a single global sketch via _r and _inst). Thanks for letting me know your thoughts.
The text was updated successfully, but these errors were encountered:
Hi @gwhitney!
Apologies for the super late answer.
You are indeed right. p5.brush cannot currently handle multiple instances simultaneously.
Over the last months I've been working on making p5.brush independent from p5, as a side project, and I have left this repository a bit outdated.
Would you be open to make necessary changes yourself through a request?
I can do it myself, but probably it will need to wait for a few more weeks
I am creating a gallery of p5 images with many p5 instances on the same web page, several of which use p5.brush. Each instance dutifully calls
brush.instance(sketch)
in the sketch function it passes to the p5 constructor, and then callsbrush.load()
in itssetup()
method. However, I get one or more occurrences ofRangeError: invalid array length
when I load the page; it's occurring ingenField()
inside of_ensureReady()
. More specifically,this.num_columns
ends up asNaN
.What seems to be happening is that one p5 instance A is registering its blend methods (in the
_registerMethods()
function), and then before those methods get called by A, another instance B has calledbrush.instance(B)
but that instance B has not yet calledsetup()
, and then whenblend()
is called by the registered methods of A, the global variables_r
and_inst
are now pointing to B, which has no width property yet, and so the number of columns is being computed to beNaN
.In other words, it seems as though p5.brush is not actually designed to handle multiple p5 instances that are setting up asynchronously, because there is only one
_r
and one_inst
variable in the module. Is that right, or is p5.brush supposed to work in this circumstance (and either I am doing something wrong or there still remains some bug in p5.brush handling multiple instances)?If p5.brush is currently not designed to handle multiple p5 sketch instances, are you interested in extending p5.brush so that it is safe to use with multiple instances of p5 all running asynchronously? Presumably this would entail keeping multiple p5 instance references around, say in some collection of objects, and making sure that the proper instance is used in any given brush function (rather that just referring to a single global sketch via
_r
and_inst
). Thanks for letting me know your thoughts.The text was updated successfully, but these errors were encountered: