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

Some thought about crashes when calling js from Nim #15

Closed
clzls opened this issue May 22, 2023 · 6 comments · Fixed by #16
Closed

Some thought about crashes when calling js from Nim #15

clzls opened this issue May 22, 2023 · 6 comments · Fixed by #16

Comments

@clzls
Copy link
Contributor

clzls commented May 22, 2023

Similar to #5 , I went into some crashes when working with hello_world.nim using Nimble package.
In devel mode it crashes silently when clicked, in release mode it works but sometimes it still crashes.
I tried to change webui.nim:261 from

data = buffer.join().strip(leading = false, chars = {'\x00'})

to

data = $(cast[cstring](addr buffer[0]))

Then it seems to work smoothly, with thread:off. Not tested much and not using nightly build, but I want to note it here for others who is willing to make further investigations about it.

My env: Nim Compiler Version 1.6.12 [Windows: amd64]

@neroist neroist linked a pull request May 22, 2023 that will close this issue
@neroist
Copy link
Contributor

neroist commented May 23, 2023

Ah, thank you for this issue and the fix! I really haven't run into this issue, I wonder why that would cause an error 🤔

@neroist
Copy link
Contributor

neroist commented May 23, 2023

I've already opened a PR but I think it would be better if you opened one instead.

@clzls
Copy link
Contributor Author

clzls commented May 24, 2023

Ah, thank you for this issue and the fix! I really haven't run into this issue, I wonder why that would cause an error 🤔

I didn't know either since no exceptions or messages were shown (either Nim side or browser side) in my case, so I didn't open a PR at the first time...

As #17 has more details about the problem, I think we could close this one.

@clzls clzls closed this as completed May 24, 2023
@clzls
Copy link
Contributor Author

clzls commented May 24, 2023

Some other thought: There are some calls returning webui-managed buffers, like encode. Would it be better if we copy the data to a Nim-managed string (by $) and destroy the returned buffers immediately? 😄

@AlbertShown
Copy link

I agree @clzl 👍
We should not forget to free the WebUI buffer using webui_free()

WebUI uses a custom memory management to allocate and free resources, so webui_free() will never cause a crash.

@AlbertShown AlbertShown reopened this May 24, 2023
neroist added a commit that referenced this issue May 24, 2023
* Fix #5, `script` crashing application

* removed unused import

* style
@neroist neroist reopened this May 24, 2023
@neroist
Copy link
Contributor

neroist commented May 24, 2023

Some other thought: There are some calls returning webui-managed buffers, like encode. Would it be better if we copy the data to a Nim-managed string (by $) and destroy the returned buffers immediately? 😄

b26d95c 🎉

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

Successfully merging a pull request may close this issue.

3 participants