Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"pointer being freed was not allocated" error on Mac #8

Open
nnahito opened this issue Apr 16, 2024 · 8 comments
Open

"pointer being freed was not allocated" error on Mac #8

nnahito opened this issue Apr 16, 2024 · 8 comments

Comments

@nnahito
Copy link

nnahito commented Apr 16, 2024

Thank you for the wonderful library.

I ran the following code on my Mac:

import uing
import strutils

var mEntry: MultilineEntry

proc extraction(_: Button) =
  echo repr(mEntry.text)

proc main = 
  let window = newWindow("Hello World!", 800, 600)

  mEntry = newMultilineEntry()

  let button = newButton("test", extraction)

  let hbox = newHorizontalBox(true)
  hbox.add(mEntry, true)
  hbox.add(button)


  window.child = hbox
  show window
  mainLoop()

init()
main()

It is a small program with Entry and buttons.
This code gets the value from Entry when the button is pressed.
At that time, the value is retrieved without any problem on Windows, but on a Mac, a memory error occurs.

malloc: *** error for object 0x10ccaa058: pointer being freed was not allocated
malloc: *** set a breakpoint in malloc_error_break to debug
SIGABRT: Abnormal termination.

Is it possible for you to correct this?
Thank you.

  • MacOS 14.1.2(23B92)
    • Apple M1 Pro
    • 16 GB
  • Nim Compiler Version 2.0.2 [MacOSX: amd64]
    • uing@0.8.0
@nnahito nnahito changed the title I get a "pointer being freed was not allocated" error on Mac "pointer being freed was not allocated" error on Mac Apr 17, 2024
@neroist
Copy link
Owner

neroist commented Apr 17, 2024

Thank you for this issue, this is odd. Do the examples at https://github.com/libui-ng/libui-ng work for you?

@nnahito
Copy link
Author

nnahito commented Apr 23, 2024

Thank you for your reply.
Sorry, what can I do with this link?
I would appreciate it if you could enlighten me!

@neroist
Copy link
Owner

neroist commented May 9, 2024

Thank you for your reply. Sorry, what can I do with this link? I would appreciate it if you could enlighten me!

@nnahito Try building and running the libui examples; instructions are in the readme

@kai-odri
Copy link

kai-odri commented Jul 2, 2024

Hi I am getting a similiar error on linux. It is only occurring when I call .text from Entry or Multiline entry.
e.g. nameEntry.text()
Im setting up my windows environment now to see if it works there.

The error message:

free(): invalid pointer
Traceback (most recent call last)
/home/kai/lightbringers/src/lightbringers.nim(126) lightbringers
/home/kai/lightbringers/src/lightbringers.nim(43) startApplication
/home/kai/.nimble/pkgs2/uing-0.8.1-92408d73d6e2e49e10c8d8d58aaaca63d0e85489/uing.nim(54) mainLoop
/home/kai/.nimble/pkgs2/uing-0.8.1-92408d73d6e2e49e10c8d8d58aaaca63d0e85489/uing.nim(80) wrapOnClick
/home/kai/lightbringers/src/insertdata_employee.nim :anonymous
/home/kai/.nimble/pkgs2/uing-0.8.1-92408d73d6e2e49e10c8d8d58aaaca63d0e85489/uing.nim(1470) text
/home/kai/.nimble/pkgs2/uing-0.8.1-92408d73d6e2e49e10c8d8d58aaaca63d0e85489/uing.nim free
SIGABRT: Abnormal termination.

OS: Arch Linux x86_64
PC: Latitude 7490 16GB
Kernel: 6.9.4-arch1-1
Nim: Nim Compiler Version 2.0.4

Edit: Runs fine on windows 10 with compiler v 2.0.6 with dynamic linking, static linking gives:

c:/users/kai/nim-2.0.6/dist/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/kai/nimcache/lightbringers_d/@mC@c@sUsers@skai@s.nimble@spkgs2@suing-0.8.1-92408d73d6e2e49e10c8d8d58aaaca63d0e85489@suing.nim.c.o:@mC@c@sUsers@skai@s.nimble@spkgs2@suing-0.8.1-92408d73d6e2e49e10c8d8d58aaaca63d0e85489@suing.nim.c:(.text+0x2fa0): undefined reference to `uiWindowOnPositionChanged'
collect2.exe: error: ld returned 1 exit status
Error: execution of an external program failed: 'C:\Users\kai\nim-2.0.6\dist\mingw64\bin\gcc.exe  @lightbringers_linkerArgs.txt'

Also quick question how would you go about implementing scrolling views?
Thanks, loving this library so far.

@neroist neroist closed this as completed in c3595b4 Jul 3, 2024
@neroist
Copy link
Owner

neroist commented Jul 3, 2024

This is probably because the code frees result and not the returned cstring from the lower-level APIs...

@neroist neroist reopened this Jul 3, 2024
@neroist
Copy link
Owner

neroist commented Jul 3, 2024

@kai-odri @nnahito Do you mind testing now with the most recent commit?

@neroist
Copy link
Owner

neroist commented Jul 4, 2024

Also quick question how would you go about implementing scrolling views?

I have no idea! libui-ng/libui-ng#281 & libui-ng/libui-ng#280 seem interesting, perhaps you could try combining those & wrapping uiScroll, uiNewScroll, and uiScrollSetChild.

@kai-odri
Copy link

kai-odri commented Jul 4, 2024

Thankyou that works fine for me on linux now. Alright cheers I've had a look at that, I am not very experienced with Nim/C I'll see how I go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants