Skip to content

Commit da018b8

Browse files
authored
Merge pull request #155 from deech/WindowSetIcon
Pass a copy of the icon image since it is freed in the Fl_Window dest…
2 parents 2a34c3b + bbc372a commit da018b8

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Graphics/UI/FLTK/LowLevel/Base/Window.chs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ import Graphics.UI.FLTK.LowLevel.Dispatch
4141
import qualified Data.Text as T
4242
import Graphics.UI.FLTK.LowLevel.Hierarchy
4343
import Graphics.UI.FLTK.LowLevel.Base.Widget
44+
import Graphics.UI.FLTK.LowLevel.RGBImage()
45+
import Control.Exception(throwIO)
46+
import System.IO.Error(userError)
4447

4548
#c
4649
enum WindowType {
@@ -320,7 +323,14 @@ instance (impl ~ ( IO (Maybe (Ref Image)))) => Op (GetIcon ()) WindowBase orig i
320323

321324
{# fun Fl_Window_set_icon as setIcon' { id `Ptr ()', id `Ptr ()' } -> `()' supressWarningAboutRes #}
322325
instance (Parent a RGBImage, impl ~ (Maybe( Ref a ) -> IO ())) => Op (SetIcon ()) WindowBase orig impl where
323-
runOp _ _ win bitmap = withRef win $ \winPtr -> withMaybeRef bitmap $ \bitmapPtr -> setIcon' winPtr bitmapPtr
326+
runOp _ _ win rgbM = do
327+
case rgbM of
328+
Nothing -> withRef win $ \winPtr -> setIcon' winPtr (castPtr nullPtr)
329+
Just rgb -> do
330+
copyIM <- copy (safeCast rgb :: Ref RGBImage) (Nothing :: Maybe Size)
331+
case copyIM of
332+
Just copyI -> withRef win $ \winPtr -> withRef copyI $ \iPtr -> setIcon' winPtr iPtr
333+
Nothing -> throwIO (userError "Could not make a copy of icon image")
324334

325335
{# fun Fl_Window_shown as shown' { id `Ptr ()' } -> `Bool' toBool #}
326336
instance (impl ~ ( IO (Bool))) => Op (Shown ()) WindowBase orig impl where

0 commit comments

Comments
 (0)