simonkrauter / NiGui

Cross-platform desktop GUI toolkit written in Nim
MIT License
718 stars 50 forks source link

Wine: Crash when getting the text field of an empty TextBox/TextArea #96

Closed chris18191 closed 4 years ago

chris18191 commented 4 years ago

When trying to set the text field of an empty TextArea the system crashes with a SIGSEGV

Log:

/home/chris/.nimble/pkgs/nigui-0.2.4/nigui.nim(1012) addLine
/home/chris/.nimble/pkgs/nigui-0.2.4/nigui.nim(2650) addLine
/home/chris/.nimble/pkgs/nigui-0.2.4/nigui.nim(1011) addText
/home/chris/.nimble/pkgs/nigui-0.2.4/nigui.nim(2648) addText
/home/chris/.nimble/pkgs/nigui-0.2.4/nigui.nim(978) text
/home/chris/.nimble/pkgs/nigui-0.2.4/nigui/private/windows/platform_impl.nim(1523) text
/home/chris/.nimble/pkgs/nigui-0.2.4/nigui/private/windows/platform_impl.nim(111) pGetWindowText
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

fixed this locally by adding the following check for characters in the pGetWindowText proc:

proc pGetWindowText(hWnd: pointer): string =
  let characters = GetWindowTextLengthW(hWnd)
  if characters == 0:
      return ""
  result = newString(characters * 2)
  var res = GetWindowTextW(hWnd, result, characters * 2 + 1)
  if res != characters: pRaiseLastOSError()
  result = result.pUtf16ToUtf8

Program runs fine on Manjaro, but crashes when running on wine. So the problem seems to be windows specific. After using the fix both versions run without problems.

simonkrauter commented 4 years ago

Thanks for reporting! I could reproduce it under Wine. Windows was not affected. It's now fixed.