0

I have a Python 2.7/PyGTK 2.24 project. I'm building on Linux Ubuntu 11.

I am using the following code to animate an image's movement across the screen.

    def move_fish():
        global fishmove, flipped
        if fishmove < 440 and flipped == False:
            fishmove = fishmove + 10
            fixed_hab.move(fish1, fishmove, 50)
            return True
        elif fishmove == 440 and flipped == False:
            pixbufanim = gtk.gdk.PixbufAnimation("IMG/IMG-FISH-L.gif")
            fish1.set_from_animation(pixbufanim)
            flipped = True
            fishmove = fishmove - 10
            fixed_hab.move(fish1, fishmove, 50)
            return True
        elif fishmove > 0 and flipped == True:
            fishmove = fishmove - 10
            fixed_hab.move(fish1, fishmove, 50)
            return True
        elif fishmove == 0 and flipped == True:
            pixbufanim = gtk.gdk.PixbufAnimation("IMG/IMG-FISH-R.gif")
            fish1.set_from_animation(pixbufanim)
            flipped = False
            return True                

    gobject.timeout_add(100, move_fish)

The code runs fine, with no compile errors or errors during runtime. However, AFTER I close the window, I get the following error multiple times. (Mind you, the fixed_hab (gtk.Fixed) and fish1 (gtk.Image) objects are at the same scope as the function declaration "def move_fish():"

Word4Word-9-16.py:1655: GtkWarning: gtk_fixed_move_internal: assertion `widget->parent == GTK_WIDGET (fixed)' failed fixed_hab.move(fish1, fishmove, 50)

Is this serious? Can I fix it? Is this going to made things difficult for the end user?

Thanks in advance!

CodeMouse92
  • 6,840
  • 14
  • 73
  • 130

1 Answers1

0

Most likely your tiemout_add fires while the application is destroyed. Your options are:

  1. Wire a destroy handler and remove the timer before exit.
  2. Topmost inside move_fish, check if the widget is destroyed and return False to end the timer.

Accessing a widget that no longer exists can fail silently but when your application logic changes, it may even segfault noisily.

aquaherd
  • 444
  • 4
  • 12