gfxdrawing example presents context in the wrong place (?)

Issue #22 new
Brett Calcott created an issue

The gfxdrawing example calls context.present() every pass through the loop. This cause flashing on OSX. I changed it calls it only calls it when the drawing changes:

diff --git a/examples/ b/examples/
--- a/examples/
+++ b/examples/
@@ -304,6 +304,7 @@
     # which function to execute next.
     curindex = 0
     draw_lines(context, 800, 600)
+    context.present()

     # The event loop is nearly the same as we used in If you
     # do not know, what happens here, take a look at for a
@@ -325,8 +326,8 @@
                 # function with the arguments.
                 func, args = functions[curindex]
+                context.present()
-        context.present()
     return 0

Comments (3)

  1. Marcus von Appen repo owner

    Changing the context as provided in your example snippet will cause artifacts to appear on other platforms, such as Windows and X11, especially, when the window is moved or another window overlaps the example window.

    This could be fixed with adding several checks for events (raising the window, movements, resize, etc.), but would defeat the purpose of the examples of being simple.

    Does the problem occur in similar C examples, too? Do you have any chance to check this?

  2. Brett Calcott reporter

    Apologies for taking so long to respond -- work overwhelm. I'm only using python for sdl2, so haven't had the chance to see if it happens elsewhere. Is there any easily installable test suites that are explicitly multi-platform?

    I've know I've seen this kind of flickering before when double-buffering was turned off. ie it looks as though I'm seeing a refresh of the image on-screen BEFORE the drawing is done. But I have no ideas double buffering works in sdl2.

    This was all I could find:

  3. Log in to comment