On Feb 4, 2010, at 12:34 PM, Henk-Jan van Tuyl wrote: > On Thu, 04 Feb 2010 04:47:57 +0100, Daniel Gorín <dgo...@dc.uba.ar> > wrote: > >> Hi >> >> I wanted to try StyledTextControl (stc) on wxHaskell. It didn't work >> right out of the box for me (test applications would die with obscure >> messages) and I couldn't find online help on what I was doing wrong. >> [...] >> >> So, the question is, is there something I can do to help other people >> having a merrier experience trying stc next time? :) > > For one thing, you could write this information in a HaskellWiki page. > > Regards, > Henk-Jan van Tuyl
Done. I put some instructions here [1] and linked it from the Building page [2]. I thought at first this might be a known issue, but in case it is not, here is a (much) longer report: 1) Steps to reproduce: Compile and run the following program: import Graphics.UI.WX import Graphics.UI.WXCore main :: IO () main = start $ do win <- frame [text := "title", visible := False] editor <- styledTextCtrl win [] set win [layout := fill $ widget editor, clientSize := sz 640 480] set win [visible := True] With wxwidgets 2.8.10, wxhaskell 0.12.1.2 (tested on OS X only), it crashes when run. If I replace styledTextCtrl by textCtrl, it loads fine. Can someone verify if it is just me? 2) Why does it crash? The call to styledTextCtrl ends up calling wxStyledTextCtrl_Create, found in wxcore/src/cpp/stc.cpp: extern "C" { #include "stc_gen.cpp" /* wxStyledTextCtrl */ EWXWEXPORT(void*,wxStyledTextCtrl_Create)(wxWindow* _prt,int _id, wxString* _txt ,int _lft,int _top,int _wdt,int _hgt,int _stl){ #ifdef wxUSE_STC return (void*) new wxStyledTextCtrl(_prt, _id, wxPoint(_lft, _top), wxSize(_wdt, _hgt), _stl, *_txt); #else return false; #endif } ... } Now, wxUSE_STC is *not* defined when I build wxcore, so wxStyledTextCtrl_Create(....) simply does "return 0", which explains the null pointer error. 3) I'm positively sure I have wxwidgets installed with stc support, so why is wxUSE_STC undefined? I don't know for sure. I find wxUSE_STC explicitly mentioned in the documentation for wxwidgets 2.9.x [3], but not in the one for 2.8.10 [4] (although, they mention "wxUSE_XXX" (sic)). It does not appear on the sources of wxMac and wxGTK 2.8.10 (in any case, according to [3] and [4], the test should be #if wxUSE_STC instead of #ifdef wxUSE_STC, but that is another story). When I explicitly define it with: cabal install wxcore --ghc-options="- D wxUSE_STC=1", the above example loads fine (I have to pass these parameters to ghc: $(wx-config --libs std,stc) when building the example) 4) Why I believe this should be fixed in wxhaskell anyway? wxhaskell includes StyledTextCtrl in its API, which implies that it needs stc built into wxwidgets (stc is an optional component of wxwidgets). But if this requirement does not hold (i.e., when wxUSE_STC is undefined for a good reason) wxhaskell builds anyway, with no warning, and eventually fails with a null pointer exception. For me, this violates the principle of least surprise. 5) How should it be fixed? I see three relatively simple possibilities, in increasing order of complexity: a) Remove all the conditional compilation stuff from stc.cpp et al. If stc is not built into wxwidgets, just fail. b) Like a), but adding a cabal flag "no-stc". If wxcore/wx are built with the no-stc flag, then StyledTextCtrl is removed from the API altogether. c) Remove all the StyledTextCtrl stuff from wxcore/wx, and move it to a separate package. What do the wxhaskell-devels think about this? If there is consensus on which should be the way forward, I'm willing to collaborate! :) Thanks, Daniel [1] http://haskell.org/haskellwiki/WxHaskell/Building_with_styledTextCtrl_support [2] http://haskell.org/haskellwiki/WxHaskell/Building [3] http://docs.wxwidgets.org/trunk/page_wxusedef.html#page_wxusedef_multi [4] http://docs.wxwidgets.org/2.8.10/wx_cppconst.html#miscellaneousconst ------------------------------------------------------------------------------ The Planet: dedicated and managed hosting, cloud storage, colocation Stay online with enterprise data centers and the best network in the business Choose flexible plans and management services without long-term contracts Personal 24x7 support from experience hosting pros just a phone call away. http://p.sf.net/sfu/theplanet-com _______________________________________________ wxhaskell-devel mailing list wxhaskell-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wxhaskell-devel