Remove seg faults (#87)

* Removed double OpenGl3Shutdown, leading to a segmentation fault in Main.hs.
* Changed nullPtr passing with Maybe to use DearImGui default arguments.
This commit is contained in:
jpwidera 2021-09-11 12:00:08 +02:00 committed by GitHub
parent cede825dff
commit 08b3139477
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 14 deletions

View File

@ -38,8 +38,6 @@ main = do
tab2 <- newIORef True tab2 <- newIORef True
loop w checked color slider r pos size' selected tab1 tab2 loop w checked color slider r pos size' selected tab1 tab2
openGL3Shutdown
loop loop
:: Window :: Window

View File

@ -283,7 +283,7 @@ getVersion = liftIO do
begin :: MonadIO m => String -> m Bool begin :: MonadIO m => String -> m Bool
begin name = liftIO do begin name = liftIO do
withCString name \namePtr -> withCString name \namePtr ->
Raw.begin namePtr nullPtr (ImGuiWindowFlags 0) Raw.begin namePtr Nothing Nothing
-- | Append items to a window. -- | Append items to a window.
-- --
@ -315,7 +315,7 @@ withFullscreen action = bracket open close (`when` action)
open = liftIO do open = liftIO do
Raw.setNextWindowFullscreen Raw.setNextWindowFullscreen
withCString "FullScreen" \namePtr -> withCString "FullScreen" \namePtr ->
Raw.begin namePtr nullPtr fullscreenFlags Raw.begin namePtr (Just nullPtr) (Just fullscreenFlags)
close = liftIO . const Raw.end close = liftIO . const Raw.end
@ -357,7 +357,7 @@ withChildOpen name action =
text :: MonadIO m => String -> m () text :: MonadIO m => String -> m ()
text t = liftIO do text t = liftIO do
withCString t \textPtr -> withCString t \textPtr ->
Raw.textUnformatted textPtr nullPtr Raw.textUnformatted textPtr Nothing
-- | Colored text. -- | Colored text.
textColored :: (HasGetter ref ImVec4, MonadIO m) => ref -> String -> m () textColored :: (HasGetter ref ImVec4, MonadIO m) => ref -> String -> m ()
@ -1369,9 +1369,9 @@ setNextWindowPos posRef cond pivotMaybe = liftIO do
Just pivotRef -> do Just pivotRef -> do
pivot <- get pivotRef pivot <- get pivotRef
with pivot $ \pivotPtr -> with pivot $ \pivotPtr ->
Raw.setNextWindowPos posPtr cond pivotPtr Raw.setNextWindowPos posPtr cond (Just pivotPtr)
Nothing -> Nothing ->
Raw.setNextWindowPos posPtr cond nullPtr Raw.setNextWindowPos posPtr cond Nothing
-- | Set next window size. Call before `begin` -- | Set next window size. Call before `begin`
-- --

View File

@ -346,10 +346,14 @@ styleColorsClassic = liftIO do
-- --
-- Passing non-null @Ptr CBool@ shows a window-closing widget in the upper-right corner of the window, -- Passing non-null @Ptr CBool@ shows a window-closing widget in the upper-right corner of the window,
-- wich clicking will set the boolean to false when clicked. -- wich clicking will set the boolean to false when clicked.
begin :: (MonadIO m) => CString -> Ptr CBool -> ImGuiWindowFlags -> m Bool begin :: (MonadIO m) => CString -> Maybe (Ptr CBool) -> Maybe (ImGuiWindowFlags) -> m Bool
begin namePtr openPtr flags = liftIO do begin namePtr (Just openPtr) (Just flags) = liftIO do
(0 /=) <$> [C.exp| bool { Begin($(char* namePtr), $(bool* openPtr), $(ImGuiWindowFlags flags)) } |] (0 /=) <$> [C.exp| bool { Begin($(char* namePtr), $(bool* openPtr), $(ImGuiWindowFlags flags)) } |]
begin namePtr (Just openPtr) Nothing = liftIO do
(0 /=) <$> [C.exp| bool { Begin($(char* namePtr), $(bool* openPtr)) } |]
begin namePtr Nothing Nothing = liftIO do
(0 /=) <$> [C.exp| bool { Begin($(char* namePtr)) } |]
begin _ Nothing _ = error "C++ default argument restriction."
-- | Pop window from the stack. -- | Pop window from the stack.
-- --
@ -394,9 +398,11 @@ sameLine = liftIO do
-- B) it's faster, no memory copy is done, no buffer size limits, recommended for long chunks of text. -- B) it's faster, no memory copy is done, no buffer size limits, recommended for long chunks of text.
-- --
-- Wraps @ImGui::TextUnformatted()@. -- Wraps @ImGui::TextUnformatted()@.
textUnformatted :: (MonadIO m) => CString -> CString -> m () textUnformatted :: (MonadIO m) => CString -> Maybe CString -> m ()
textUnformatted textPtr textEndPtr = liftIO do textUnformatted textPtr (Just textEndPtr) = liftIO do
[C.exp| void { TextUnformatted($(char* textPtr), $(char* textEndPtr)) } |] [C.exp| void { TextUnformatted($(char* textPtr), $(char* textEndPtr)) } |]
textUnformatted textPtr Nothing = liftIO do
[C.exp| void { TextUnformatted($(char* textPtr)) } |]
-- | Shortcut for @PushStyleColor(ImGuiCol_Text, col); Text(fmt, ...); PopStyleColor();@. -- | Shortcut for @PushStyleColor(ImGuiCol_Text, col); Text(fmt, ...); PopStyleColor();@.
-- --
@ -1086,9 +1092,11 @@ isItemHovered = liftIO do
-- | Set next window position. Call before `begin` Use pivot=(0.5,0.5) to center on given point, etc. -- | Set next window position. Call before `begin` Use pivot=(0.5,0.5) to center on given point, etc.
-- --
-- Wraps @ImGui::SetNextWindowPos()@ -- Wraps @ImGui::SetNextWindowPos()@
setNextWindowPos :: (MonadIO m) => Ptr ImVec2 -> ImGuiCond -> Ptr ImVec2 -> m () setNextWindowPos :: (MonadIO m) => Ptr ImVec2 -> ImGuiCond -> Maybe (Ptr ImVec2) -> m ()
setNextWindowPos posPtr cond pivotPtr = liftIO do setNextWindowPos posPtr cond (Just pivotPtr) = liftIO do
[C.exp| void { SetNextWindowPos(*$(ImVec2* posPtr), $(ImGuiCond cond), *$(ImVec2* pivotPtr)) } |] [C.exp| void { SetNextWindowPos(*$(ImVec2* posPtr), $(ImGuiCond cond), *$(ImVec2* pivotPtr)) } |]
setNextWindowPos posPtr cond Nothing = liftIO do
[C.exp| void { SetNextWindowPos(*$(ImVec2* posPtr), $(ImGuiCond cond)) } |]
-- | Set next window size. Call before `begin` -- | Set next window size. Call before `begin`