Ticket #1205: tree-model-sort-crash.hs

File tree-model-sort-crash.hs, 1.3 kB (added by guest, 4 years ago)

Run with --crash to reproduce the crash.

Line 
1import Graphics.UI.Gtk
2import System.Environment (getArgs)
3import Control.Monad (when)
4
5main :: IO ()
6main = do
7    initGUI
8    window <- windowNew
9
10    realStore <- listStoreNew [("o hai", 3)]
11    store <- treeModelSortNewWithModel realStore
12    view <- treeViewNewWithModel store
13
14    col <- treeViewColumnNew
15    treeViewColumnSetTitle col "Foo"
16    renderer <- cellRendererTextNew
17    cellLayoutPackStart col renderer True
18
19    -- This works fine, but it's annoyingly verbose. We should be able to use
20    -- the wrapped model just like any other model.
21    cellLayoutSetAttributeFunc col renderer store $ \iter -> do
22        childIter <- treeModelSortConvertIterToChildIter store iter
23        (str, n) <- treeModelGetRow realStore childIter
24        set renderer [ cellText := str ]
25
26    -- On the other hand, this compiles, but when the view is rendered crashes
27    -- with
28    --   ** (test:26137): CRITICAL **: gtk2hs_store_get_impl: assertion
29    --      `GTK2HS_IS_STORE(store)' failed
30    --    zsh: segmentation fault  ./test wrapped
31    -- I haven't looked into this very far.
32    args <- getArgs
33    when (args == ["--crash"]) $
34        cellLayoutSetAttributes col renderer store $
35            \(str, n) -> [ cellText := str ]
36
37    treeViewAppendColumn view col
38
39    containerAdd window view
40    widgetShowAll window
41    window `onDestroy` mainQuit
42
43    mainGUI