Hello.

I am writing an application which uses Haskell threads to execute some
long tasks.

I have tried to isolate the issue in a small program which is attached
to this message.

When updating a sorted tree model in a separate thread, most of the time
the application crashes with a critical error:

  (TreeSort:15588): Gtk-CRITICAL **: 
IA__gtk_tree_model_sort_convert_iter_to_child_iter: assertion `VALID_ITER 
(sorted_iter, tree_model_sort)' failed
  TreeSort: user error (ListStore.getRow: iter does not refer to a valid entry)

There are two buttons in the application: only one uses a separate
thread. Keep pressing it and soon the application will crash. With the
other button it does not crash.

Is this a known bug?

What would be a fix or an workaround for this issue?

Romildo
import Graphics.UI.Gtk
import Control.Concurrent (yield, forkIO)
import Control.Monad (forM_)
import Data.IORef (newIORef, readIORef, writeIORef)

sortFunc rawmodel selector iter1 iter2 =
  do x1 <- treeModelGetRow rawmodel iter1
     x2 <- treeModelGetRow rawmodel iter2
     return (compare (selector x1) (selector x2))

mkSortCol view model rawmodel maybeSort title mkCellRenderer attribs f =
  do col <- treeViewColumnNew
     treeViewColumnSetTitle col title
     treeViewColumnSetResizable col True
     treeViewColumnSetSizing col TreeViewColumnAutosize
     rend <- mkCellRenderer
     treeViewColumnPackStart col rend True
     set rend attribs
     cellLayoutSetAttributeFunc col rend model $ \iter ->
       do putStrLn (">>> DEBUG attributeFunc " ++ title)
          cIter <- treeModelSortConvertIterToChildIter model iter
          row <- treeModelGetRow rawmodel cIter
          set rend (f row)
          putStrLn ("<<< DEBUG attributeFunc " ++ title)
     treeViewAppendColumn view col
     case maybeSort of
       Just (id,selector) ->
         do treeSortableSetSortFunc model id $ sortFunc rawmodel selector
            treeViewColumnSetSortColumnId col id
       Nothing ->
         return ()
     return rend

main =
  do ref <- newIORef 0
     initGUI
     timeoutAddFull (yield >> return True) priorityDefaultIdle 50
     win <- windowNew
     rawmodel <- listStoreNew []
     model <- treeModelSortNewWithModel rawmodel
     treeSortableSetDefaultSortFunc model $ Just $ sortFunc rawmodel fst
     view <- treeViewNewWithModel model
     let nothing = Nothing :: Maybe (SortColumnId, a -> ())
     mkSortCol view model rawmodel nothing "Name" cellRendererTextNew [] $ \(x,_) -> [cellText := x]
     mkSortCol view model rawmodel (Just (2,snd)) "Number" cellRendererTextNew [] $ \(_,y) -> [cellText := show y]
     box <- vBoxNew False 2
     containerAdd win box
     boxPackStart box view PackGrow 2
     let flushModel =
           do listStoreClear rawmodel
              treeViewSetCursor view [0] Nothing
              forM_ [1..10] $ \_ ->
                do counter <- readIORef ref
                   putStrLn (show counter)
                   writeIORef ref (counter + 1)
                   listStoreAppend rawmodel (":" ++ show counter,counter)
     button1 <- buttonNewWithMnemonic "_Flush within forkIO"
     boxPackStart box button1 PackGrow 2
     on button1 buttonActivated $ forkIO flushModel >> return ()
     button2 <- buttonNewWithMnemonic "_Flush without forkIO"
     boxPackStart box button2 PackGrow 2
     on button2 buttonActivated $ flushModel
     widgetShowAll win
     onDestroy win mainQuit
     mainGUI
------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
Gtk2hs-devel mailing list
Gtk2hs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gtk2hs-devel

Reply via email to