Anut-py / h-raylib

Haskell bindings for raylib
https://hackage.haskell.org/package/h-raylib
Apache License 2.0
84 stars 14 forks source link

Drag and drop does not work as expected #48

Closed delyan-kirov closed 7 months ago

delyan-kirov commented 7 months ago

Trying to drag and drop files fails. Particularly using the function loadDroppedFiles will seg fault while trying to free an invalid pointer to the file path:

free(): invalid pointer
Aborted (core dumped)

Or it will try to double free:

free(): double free detected in tcache 2
Aborted (core dumped)

It does that on the next frame or the frame after. I'm not sure if this is user error, because I don't know what I should or should not free manually and how. This is a basic version of what I tried:

mainloop :: AppState -> IO AppState
mainloop appState = do
  fileIsDropped <- isFileDropped
  when fileIsDropped $
    print =<< loadDroppedFiles
  endDrawing
  return appState''

main = whileWindowOpen_ mainloop =<< initApp
delyan-kirov commented 7 months ago

While working on my little applet, I found that using the foreign C functions will not crash the app and will give the correct pointer and the correct file path.

  fileIsDropped <- isFileDropped
  when fileIsDropped $ do
    filePtr <- c'loadDroppedFiles
    print filePtr
    fileData <- peek filePtr
    print fileData
    c'unloadDroppedFiles filePtr
Anut-py commented 7 months ago

Fixed in 5.1.2.0