Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Freezing loop #348

Closed
birbilis opened this issue Jul 19, 2016 · 6 comments
Closed

Freezing loop #348

birbilis opened this issue Jul 19, 2016 · 6 comments

Comments

@birbilis
Copy link

birbilis commented Jul 19, 2016

I see generated code of the following style:

  temp = (function() {
    while (MousePrims.isDown()) {

    }
    world.observer.setGlobal("dragging?", false);
  });
  procs["waitMouseUp"] = temp;
  procs["WAIT-MOUSE-UP"] = temp;

that causes freezing of Firefox

The compiler should never generate such tight (with no code in them) loops I think if Javascript can't handle them. Should have some small sleep in there. In Java even sleep(0) worked to avoid freezing

@birbilis
Copy link
Author

Please see this screenshot:
screenshot 2016-07-19 17 24 17

@birbilis
Copy link
Author

birbilis commented Jul 19, 2016

this correspondes to this code of mine:

to wait-mouse-up
  while [mouse-down?] []
  set dragging? false
end

that works fine in NetLogo Desktop

@birbilis
Copy link
Author

I tried adding a "wait 0" in case it would help, but I get back "Error", "unimplemented primitive: wait" message. What other NOP-style command could I use inside that tight loop?

@birbilis
Copy link
Author

btw, note that Firefox becomes unresponsive even if one presses Stop Script at the respective dialog. You have to press Debug script, then close the tab

@TheBizzle
Copy link
Member

Should have some small sleep in there. In Java even sleep(0) worked to avoid freezing

There is no such thing in JavaScript, which is a single-threaded environment. This problem is the same one that prevents wait from being implemented.

This problem is on our radar and is something that we want to fix soon. However, solving these sorts of problems for NetLogo in a general way, in JavaScript, is not straightforward or easy.

Closing as duplicate of NetLogo/Tortoise#151 .

@birbilis
Copy link
Author

Indeed, had discussed this in the past and had forgotten about it. Would expect the whole netlogo program though to run on a background worker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants