-
Notifications
You must be signed in to change notification settings - Fork 28
Description
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.