ch3ll0v3k / pybox2d

Automatically exported from code.google.com/p/pybox2d
Other
0 stars 0 forks source link

pyglet/test_main.py raising an exception when a test is closed. Also a set_fps_limit() is not needed anymore #11

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Every time I closed a test on the ported to pyglet testbed an exception was
raised, on Mac OS X at least. The traceback is displayed bellow and the
problem I think was a race condition between the closing of the window and
the drawing of the last frame (which I think is strange).

-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-traceback-*-*-*-*-*-*-*-*-*-*-*-*-
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-traceback-*-*-*-*-*-*-*-*-*-*-*-*-

Apfelstrudel:pyglet santagada$ python test_Car.py 
----------------------------------
Loading Car...
Traceback (most recent call last):
  File "test_Car.py", line 190, in <module>
    main(Car)
  File
"/Users/santagada/projects/pybox2d/Python/testbed/pyglet/test_main.py",
line 971, in main
    test.run()
  File
"/Users/santagada/projects/pybox2d/Python/testbed/pyglet/test_main.py",
line 631, in run
    pyglet.app.run()
  File "/Library/Python/2.5/site-packages/pyglet/app/__init__.py", line
264, in run
    EventLoop().run()
  File "/Library/Python/2.5/site-packages/pyglet/app/carbon.py", line 84,
in run
    self._timer_proc(timer, None, False)
  File "/Library/Python/2.5/site-packages/pyglet/app/carbon.py", line 133,
in _timer_proc
    sleep_time = self.idle()
  File "/Library/Python/2.5/site-packages/pyglet/app/__init__.py", line
187, in idle
    dt = clock.tick(True)
  File "/Library/Python/2.5/site-packages/pyglet/clock.py", line 696, in tick
    return _default.tick(poll)
  File "/Library/Python/2.5/site-packages/pyglet/clock.py", line 303, in tick
    item.func(ts - item.last_ts, *item.args, **item.kwargs)
  File
"/Users/santagada/projects/pybox2d/Python/testbed/pyglet/test_main.py",
line 836, in SimulationLoop
    self.debugDraw.batch.draw()
  File "/Library/Python/2.5/site-packages/pyglet/graphics/__init__.py",
line 538, in draw
    func()
  File
"/Users/santagada/projects/pybox2d/Python/testbed/pyglet/test_main.py",
line 176, in set_state
    gl.gluOrtho2D(0, self.window.width, 0, self.window.height)
  File "/Library/Python/2.5/site-packages/pyglet/gl/lib.py", line 105, in
errcheck
    raise GLException(msg)
pyglet.gl.lib.GLException: invalid value

-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-traceback-*-*-*-*-*-*-*-*-*-*-*-*-
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-traceback-*-*-*-*-*-*-*-*-*-*-*-*-

If I print the values of self.window.width and self.window.height they are
both 0.

Also from
http://www.pyglet.org/doc/programming_guide/new_features_replacing_standard_prac
tice.html#application-event-loop
:

"Usually applications can update at a less frequent interval. For example,
a game that is designed to run at 60Hz can use clock.schedule_interval:

def update(dt):
    pass
clock.schedule_interval(update, 1/60.0)

This also removes the need for clock.set_fps_limit."

here is my patch:

===================================================================
--- test_main.py    (revision 105)
+++ test_main.py    (working copy)
@@ -502,6 +502,13 @@
         self.world.SetContactListener(self.contactListener)
         self.world.SetDebugDraw(self.debugDraw)

+    def on_close(self):
+        """
+        Callback: user tried to close the window
+        """
+        pyglet.clock.unschedule(self.SimulationLoop)
+        super(Framework, self).on_close()
+
     def on_show(self):
         """
         Callback: the window was shown.
@@ -627,7 +634,6 @@
         """
         if self.settings.hz > 0.0:
             pyglet.clock.schedule_interval(self.SimulationLoop, 1.0 /
self.settings.hz)
-            pyglet.clock.set_fps_limit(1.0 / self.settings.hz)
         pyglet.app.run()

     def SetTextLine(self, line):

Original issue reported on code.google.com by santagada on 26 Oct 2008 at 1:40

GoogleCodeExporter commented 8 years ago
Nice one. The pyglet testbed, as you can see, still needs a bunch of work.

Fixed in r106.

Original comment by sir...@gmail.com on 26 Oct 2008 at 3:47