Threading crash with hxcpp

Can anyone help with this haxe/c++ problem?
I’m using OpenFL (hxCpp) and a c++ library (phidgets) that uses threading.

Now If i try to create a thread in haxe using Thread.create then everything crashes. Debugging using visual studio and hxcpp ends up with a nullptr exception.

**"this was nullptr."**
myapp.exe!hx::StackContext::pushFrame(hx::StackFrame * inFrame) Line 420	C++
myapp.exe!hx::StackFrame::StackFrame(const hx::StackPosition * inPosition) Line 594	C++

Is there some kind of thread collision here? The c++ lib runs fine if i dont try to create a thread using haxe.
Not sure how to fix this, does anyone have some insight?

Thanks

Does it crash just by calling Thread.create, or is anything else required to cause the crash? OpenFL uses threads already for a few different things, are those causing a crash? (for example, URLLoader or Assets.load* calls)

Thread.create does run and the thread starts. The problem is when the c++ execution arrives at this function (elsewhere)

**(c++ GENERATED OUTPUT)**

void Phidgets_obj::_onAttach( ::CPhidgetHandle ph){
            	HX_STACKFRAME(&_hx_pos_1632770cc34635bc_359__onAttach)
            	}

Now, this HX_STACKFRAME is creating the nullptr crash. And this does not happen if Thread.create is not started elsewhere. Now, looking further into the stackframe code it seems the error comes from this:

ctx =  hx::gMultiThreadMode ? hx::tlsStackContext : hx::gMainThreadContext;
ctx->pushFrame(this);
**"this was nullptr."**

I also get this error :

Bad local allocator - requesting memory from unregistered thread!

That seems to be thread related, but i’m a little lost from here on…

Its perhaps not really a OpenFL question, but any pointers would be very truly appreciated :slight_smile:

You might want to bring @Hugh_Sanderson to this discussion as he knows everything about how threading works in hxcpp.