"add an instance" issue

Report bugs. Post bug workarounds or fixes

Moderator: MSandro

Post Reply
MrSteve
Posts: 61
Joined: Jun 16th, '16, 01:22

"add an instance" issue

Post by MrSteve » Aug 4th, '16, 22:24

two issue:

1) click on add an instance block and it never ends
2) click on "+" to right of "Clear" and system "hangs"

Seems the "add an instance" has an implied "and wait"

Thanks to GP workshop participant who found this issue.
Attachments
addInstanceBug.gpp
(5.36 KiB) Downloaded 289 times

JohnM
Posts: 379
Joined: Sep 11th, '15, 14:42

Re: "add an instance" issue

Post by JohnM » Aug 8th, '16, 00:25

Yes, you're exactly right. The current implementation waits for the initialize script to finish before proceeding. Thus, if the initialize script has a forever loop, it blocks everything. Since broadcasts normally spawn a new task (even "broadcast and wait" does; it just waits for the task(s) to finish), it's perfectly reasonable to expect this to work. We saw a similar problem at the workshop where someone called the "ask" block (which waits for user input) in an initialization script. (Maybe you saw that, too.)

I'm thinking of replacing the current confusing mechanism with a new hat block, "when instantiated," that does run in its own task when a new instance is created. Such a script could do initialization, start a "forever" loop, wait for user input -- whatever -- because the caller would proceed without waiting for the script to finish. That would do the expected thing with the given project.

For situations that require high performance initialization (e.g. the Pixel extension, which creates new instances of the Pixel helper class for every pixel in an image, potentially hundreds of thousands of them), one can use an "initialize" method added with the button in the "My Blocks" palette. Users of that feature need to understand that the initialize method is called synchronously and thus should not block or loop indefinitely. However, this feature would only be available in developer mode.

Post Reply