Chris Mears <[EMAIL PROTECTED]> writes:

> I am using the wxHaskell library built from the Darcs repository at
> haskell.org, with wxWidgets "gtk-2.6.3" and GHC 6.6.  I am trying to
> draw a polygon with the "polygon" function, but it isn't doing what I
> expected.
[...]
> From some experimentation, it seems that the first line is drawn
> correctly, but the subsequent ones are drawn from the origin instead of
> from the previous point, and the last point is ignored altogether.

I think I have tracked down the source of the problem.  It works
correctly on my 32-bit computer, but misbehaves on the 64-bit one.
Summary: On my 64-bit machine, Haskell Int is 64-bit, C int is 32-bit.

The polygon function takes a list of Point, where a Point is a pair
(basically) of Ints.  On 64-bit GHC, an Int is 64-bits long, so each
component of a Point is 64-bits.  The Point components are marshalled
into an array and passed to C code (wxc/src/ewxw/eljdc.c).  The C code
treats the array as an array of (C) int.  However, on the 64-bit machine
a C int is 32-bits.

So, when I passed the 64-bit points (50, 50), (100, 100), etc. as 32-bit
points they were interpreted as (50, 50), (0, 0), (100, 100), etc.,
which explains the strange drawing I saw.  Changing the cast in the C
code from (int*) to (long*) corrects the problem, but is not a general
fix.  Sadly, I don't know enough about FFI and marshalling to suggest
the proper correction.

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
wxhaskell-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wxhaskell-users

Reply via email to