Skip to content

Crash on access to ListStore GValue #320

@int-index

Description

@int-index

Here's a simple application:

import Data.Text (Text, pack)
import Control.Monad
import System.Exit
import qualified GI.Gio as Gio
import qualified GI.Gtk as Gtk
import qualified Data.GI.Base.GType as Gtk

main :: IO ()
main = do
  m_app <- Gtk.applicationNew (Just (pack "serokell.debug.trigger-gvalue-bug-app")) []
  app <- maybe (die "could not create app") return m_app
  void $ Gio.onApplicationActivate app $ do
    window <- Gtk.applicationWindowNew app

    -- Create listStore and treeView
    listStore <- Gtk.listStoreNew [Gtk.gtypeString]
    treeView <- Gtk.treeViewNewWithModel listStore
    do column <- Gtk.treeViewColumnNew
       renderer <- Gtk.cellRendererTextNew
       void $ Gtk.treeViewColumnSetTitle column (pack "First Column")
       void $ Gtk.treeViewColumnPackStart column renderer False
       void $ Gtk.treeViewColumnAddAttribute column renderer (pack "text") 0
       void $ Gtk.treeViewAppendColumn treeView column
       void $ Gtk.treeViewSetHeadersVisible treeView True

    -- Fill the first cell
    do value <- Gtk.toGValue (Just "First Cell" :: Maybe String)
       iter <- Gtk.listStoreAppend listStore
       Gtk.listStoreSet listStore iter [0] [value]

    void $ Gtk.onTreeViewCursorChanged treeView $ do
      (mTreePath, _) <- Gtk.treeViewGetCursor treeView
      case mTreePath of
        Nothing -> die "No iterator"
        Just treePath -> do
          (isValid, iter) <- Gtk.treeModelGetIter listStore treePath
          unless isValid $ die "Invalid iterator"
          gvalue <- Gtk.treeModelGetValue listStore iter 0
          -- Trigger the bug
          Just s <- Gtk.fromGValue gvalue :: IO (Maybe String)
          putStrLn s

    Gtk.containerAdd window treeView
    Gtk.widgetShowAll window
  void $ Gio.applicationRun app Nothing

When built with old nixpkgs (1ssisvdqj3xwg5q0n7sdx27glnfx6p0a1jgi4labfylxlalc7bzm), it renders a simple window.

When built with newer nixpkgs (1179840f9a88b8a548f4b11d1a03aa25a790c379), it crashes with the following error message:

(ghc:19451): GLib-GObject-CRITICAL **: 01:16:38.003: g_value_get_string: assertion 'G_VALUE_HOLDS_STRING (value)' failed
Bug.hs: user error (Pattern match failure in do expression at Bug.hs:40:11-16)
Bug.hs: interrupted
Bug.hs: warning: too many hs_exit()s

The compiler version is GHC 8.10.1 in both cases.

I haven't quite figured out what exactly goes wrong here and what component is at fault. Could be gtk+ itself, could be haskell-gi.

I've spent plenty of time following false leads, but now that I've got a minimized example to reproduce the issue, I'm going to find the exact nixpkgs commit that causes the regression.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions