3

Using GHC 7.4.2 and GtkHs 0.12.4, on Win32 and Win64, this program takes more and more memory, consuming approximately 2Mb/sec on my machine. I am simply trying to make an animation using Gtk (this is why I invalidate the window so it gets redrawn immediately).

I tried to profile the memory usage with the RTS options, but this memory is not visible.

What is going on ?

import Graphics.UI.Gtk

main :: IO ()
main = do
    initGUI
    window <- windowNew
    onDestroy window mainQuit
    onExpose window (\_ -> widgetQueueDraw window >> return True)
    widgetShowAll window
    mainGUI

-- Edit: I am using the version of Gtk found here which happens to be 2.24.10

-- Edit2: So, using an external timer instead of requesting widgetQueueDraw from the expose event fixes the problem. It will do for now, but I don't understand why. I have used this approach in several languages with several GUI framework (invalidating a GUI control in the paint event). Usually, calling the invalidate just sets a flag that gets read next time the GUI thread kicks in. It ends-up in the GUI thread redrawing the control each frame, but that is actually what I want here. It looks like a but in Gtk2Hs.

4

1 回答 1

0

我认为你的程序进入了一个循环。当窗口接收到暴露事件(即请求重绘自身)时,您不进行任何绘图。相反,你强制它重绘自己,这反过来会发出一个暴露事件,等等。您必须将问题分成两部分。您应该设置一个计时器,该计时器调用一个准备动画下一步的函数,并调用widgetQueueDraw将场景渲染到窗口上。实际渲染应该作为对窗口暴露事件的反应。

于 2013-04-27T14:16:20.203 回答