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

Embedding an nREPL server in lwjgl example results in crash on connection attempt #59

Closed
jdhollis opened this issue Nov 22, 2020 · 5 comments

Comments

@jdhollis
Copy link

jdhollis commented Nov 22, 2020

I’m attempting to spin up an nREPL server from within my app (which I’m basing off the lwjgl example). The app starts up fine, but it crashes as soon as I try to connect to the server (using Cursive’s nREPL connection type):

# Problematic frame:
# C  [libskija.dylib+0x4502d]  SkCanvas::internalDrawPaint(SkPaint const&)+0xcd

My goal is to enable interactive development for me while running the app on the main thread and to eventually include the REPL as a feature of the app. (This was an attempt to follow @tonsky's advice in #56.)

The only change I’ve made to the example so far is a call to start the REPL server just before the main loop:

(repl-server/start!)
(loop []
  (when (not (GLFW/glfwWindowShouldClose window))
    (draw canvas)
    (.flush context)
    (GLFW/glfwSwapBuffers window)
    (GLFW/glfwPollEvents)
    (recur)))

My start! function is fairly simple. I also tried wrapping everything in a fresh thread to no avail:

(defn start!
  []
  (if (nil? @thread)
    (do
      (reset! thread (Thread. ^Runnable
                              (fn [] (if (nil? @server)
                                       (reset! server (start-server :port 12345))))))
      (.start @thread))))

I’m currently at a loss as to what else to try.

I've attached the crash log. Any suggestions?

hs_err_pid99984.log

@jdhollis
Copy link
Author

I tried the same approach using the clojure.core.server/start-server instead of nREPL, and when I tried to connect, it crapped out with a similar message:

# Problematic frame:
# C  [libskija.dylib+0x4502d]  SkCanvas::internalDrawPaint(SkPaint const&)+0xcd

@tonsky
Copy link
Collaborator

tonsky commented Nov 22, 2020

Very strange. I can reproduce it, and it seems to be related to Skija specifically, if I remove it and leave LWJGL only, it doesn’t crash. I’ll look into it too, thanks for reporting!

@tonsky
Copy link
Collaborator

tonsky commented Nov 23, 2020

I think the problem is that connecting via nREPL triggers GC which collects BackendRenderTarget and Surface. Adding (println context target surface) after the infinite loop solves the problem. I’ll fix Skija tomorrow so that Canvas holds a reference to the Surface so that it won’t be collected before Canvas is.

@tonsky tonsky closed this as completed in 593ec4d Nov 23, 2020
@tonsky
Copy link
Collaborator

tonsky commented Nov 23, 2020

Should work fine in 0.6.14. Let me know if it doesn’t

@jdhollis
Copy link
Author

Finally getting back into this. 0.6.18 works fine for me. Thanks!

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

2 participants