-
Notifications
You must be signed in to change notification settings - Fork 191
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
Body.sleep doesn't seem to work properly #251
Comments
Humm, sounds strange. The best is if you can make a small example that reproduces this error, otherwise its difficult to troubleshoot. Also, if you see any error print out please write them here as well. |
There may be a problem with my statement, it seems that the program is stuck while calling sleep() instead of debug_draw(). Here is an example, when you click the mouse will only print "start call sleep()", and then the window remains unresponsive, after a period of time automatically quit with no error. import pymunk
import pygame as pg
import sys
from pymunk.pygame_util import DrawOptions
screen = pg.display.set_mode((1000, 600))
draw_options = DrawOptions(screen)
space = pymunk.Space()
space.gravity = (0, 100)
body = pymunk.Body()
body.position = (100, 100)
shape = pymunk.Circle(body, 20)
shape.mass = 1
space.add(body, shape)
clock = pg.time.Clock()
while True:
for event in pg.event.get():
if event.type == pg.QUIT:
pg.quit()
sys.exit()
elif event.type == pg.MOUSEBUTTONDOWN and event.button == 1:
## click the left button of the mouse
print("start call sleep()")
body.sleep()
print("end call sleep()")
screen.fill((255, 255, 255))
print("Start debug_draw()")
space.debug_draw(draw_options)
print("End debug_draw()")
space.step(1 / 60)
pg.display.flip()
clock.tick(60) |
Ah Then I understand. You can see the error printed out I believe:
When you run it in idle, do you see both the print lines you added and also the Aborting error? The error is because you did not set a sleep threshold on the space: http://www.pymunk.org/en/latest/pymunk.html#pymunk.Space.sleep_time_threshold In your code you can set it right after you set the gravity, like this:
When you manual call the sleep the value of If you want a full example how it can work you can check the |
Answering myself: No, the error is not printed when run from IDLE. I will investigate a bit how to improve this, very difficult to find out whats wrong if you dont see the error! |
When I call sleep on a body,the window keeps sticking and the program exits automatically(I use IDLE as my program editor). Is there a problem?
The text was updated successfully, but these errors were encountered: