wikiti / extension-networking

Library developed for OpenFL to facilitate connections between applications, using TCP sockets, and following the scheme of event-driven programming.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"Critical Error: Allocating from a GC-free thread" when using VSCode debugger

neillrobson opened this issue · comments

I am not certain that the issue I am experiencing is directly related to this library. However, after producing this minimal example, I believe that some connection may exist.

Versions:

  • Haxe: 4.0.0-preview.4+1e3e5e016
  • Lime: 7.0.0
  • OpenFL: 8.4.1
  • extension-networking: 1.4.2
  • hxcpp: 4.0.4
  • hxcpp-debug-server (i.e. hxcpp debugger): 1.0.0
  • Visual Studio Code: 1.26.1

Steps to reproduce:

  1. Open the folder examples/basic-example in Visual Studio Code.

  2. Set Build Target to Windows, Build Configuration to Debug.

  3. Ctrl-Shift-B to build (lime build windows -debug --connect 6000)

  4. In the Debug sidebar, select a Windows/HXCPP configuration.

    I used the following:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Hxcpp",
            "type": "hxcpp",
            "request": "launch",
            "program": "${workspaceRoot}/bin/windows/bin/basic-example.exe"
        }
    ]
}
  1. Start debugging.

The program begins fine, but as soon as I click "Server," I get the message Critical Error: Allocating from a GC-free thread and the program terminates.

If I try to simply run the same program (no recompilation) without debugging (lime run windows -debug --connect 6000), everything seems to work as expected.

Hey @RNanoware !

Thank you for your report.

After googling a bit, and checking hxcpp's repo, I found that that error is raised from this line. This library uses a custom thread wrapper that migh cause this issue; threads are used both in client and server side. If that's the case, the this error should pop on both sides.

Does this issue also happens on a debugging client if you try to connect to a non-debugging server?

Just tried selecting "client" on a debug window, both with and without another (non-debugging) window running a server. The result in both cases was the same: the client window closed immediately and the same GC thread error appears in the console.

Thank you for looking into this so promptly!

Hey @RNanoware !

I've created this branch with a simple example to see if we can isolate the problem.

Could you please try to run that example (ccp target) and see if it gives you any trouble? I should display a cube, and, if you press it, it disappears for 2 seconds.

That example seems to work just fine! I build the project (lime build windows -debug --connect 6000), then debug using the default HXCPP configuration (mentioned in the previous comment). When the cube appears, I click it, and it goes away for two seconds, then reappears. I can repeat the process multiple times. No errors appear in the console. Full console output:

src/Main.hx:46: Thread start
src/Main.hx:55: Thread end
src/Main.hx:46: Thread start
src/Main.hx:55: Thread end

The "thread start" appears shortly after the cube disappears, and the "thread end" shows up slightly after the cube reappears on the screen.

Hope this helps! I may try to look at some of the code to see if I can figure out anything else.

@RNanoware Looks like cpp threads are not the problem.

Does your VS code debugger allow you to step on the library's code? Perhaps you could find which line (or backtrace, or context) is raising that error.

Alright, I found the line that is causing the error, and it seems that threads may actually be the root cause:

https://github.com/wikiti/extension-networking/blob/master/src/networking/wrappers/ThreadWrapper.hx#L54

More specifically, the program terminates within the create call of the underlying Haxe thread class.

I'm going to put a breakpoint on that line and see what else I can figure out.

Edit: Put a breakpoint on that line in the basic-example on the bugs/threads branch, and the breakpoint was never hit--both server and client ran just fine while debugging. Hmm. Going back to my Haxeflixel project (where I originally encountered the error) still doesn't work.