3

I am working on a project, and one of our spec is to be able to display PGM images with TKinter. Well, for some reason, after switching the image a specific number of times, our application would always end with a Segmentation Fault...

For debugging purposes, I then made a very simple TKinter program that lists all the images in a directory, and lets the user switch the displayed one using a slider. This program has the same issue: after every 26th image, I get a segmentation faut with a "malloc(): memory corruption".

Here is my debug code:

#!/usr/bin/python3

from tkinter import *
import os

class MainFrame():

  def __init__(self, main):
    self.input_canvas = Canvas(main, width=640, height=480)
    self.input_canvas.grid(column=1, row=1)

    self.token = False

    self.files = os.listdir('.')
    self.files.sort()

    self.scale = Scale(main, orient='horizontal', from_=0, to=len(self.files), resolution=1,
            tickinterval=1/len(self.files), length=600, command=self.load_image)
    self.scale.grid(column=1, row=2)

    self.load_image("0")


  def load_image(self, scale_value):
    # The token is only here to make sure load_image is not called multiple times at the same time
    if not self.token:
      self.token = True
    else:
      return

    input_pic = PhotoImage(file=self.files[int(scale_value)])

    self.input_canvas.create_image(0, 0, anchor=NW, image=input_pic)
    self.input_canvas.image = input_pic

    self.token = False


if __name__ == '__main__':
  root = Tk()
  MainFrame(root)
  root.mainloop()

I guess I encountered a bug with TKinter, but I didn't find any information about that, so maybe I'm doing something wrong that I just can't see :/

Also, I wanted to use PIL with the ImageTk module, but for some reason it couldn't open our test images (they were blank).

Here is an archive with some of our test images (those are 16bits PGM): https://mega.nz/#!CkxwzaZK!2d0vf4ORHh9H9LqWeKpfaZDTPrsmM89lYntrlO44AOE

Any help is welcome!

RhiobeT
  • 31
  • 4
  • Can you give more information about where does the segmentation fault occur? – Benjamin Barrois Jan 31 '18 at 09:35
  • Have you also tried perhaps using a `label` to display the images as well? How did that work? Same error? A different one? – Nae Jan 31 '18 at 09:38
  • 1
    @BenjaminBarrois I tried to find that using print calls, but it's a bit inconsistent... It's either after the PhotoImage creation, or the create_image call – RhiobeT Jan 31 '18 at 09:41
  • I don't know this python package, but there is a strange thing here: you class takes `Frame` as a parameter and it is never used. Maybe your problem is linked to this. – Benjamin Barrois Jan 31 '18 at 09:45
  • 2
    @Nae I just checked, and the same problem happens using Labels – RhiobeT Jan 31 '18 at 09:50
  • @BenjaminBarrois Looks like it was a mistake, I edited my first post. It wasn't the problem though :/ – RhiobeT Jan 31 '18 at 09:55

0 Answers0