Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

[.net] C++/CLI Thread problem

Started by smitty1276 1 reply 2.4k views
Original Post
smitty1276
smitty1276
Using C++/CLI, I have an instance function which I intend to be the entry point for a thread... I start it up like so...

Threading::ThreadStart^ ts = gcnew Threading::ThreadStart(this,
   &MyClass::TheThreadFunc);

Threading::Thread^ t = gcnew Threading::Thread(ts);
t->Start();

That seems to work, sort of. The thread starts running, but I get a NullReferenceException inside of the thread worker function when it tries to access an member object reference. Is there something I am doing wrong that could cause this? I've never played with C++/CLI extensively before.
gharen2
gharen2
There's a ton of different things that can cause this, and not enough info provided to tell which it is. Maybe post more code?

Are you certain that you didn't just forget to assign something to the member?
smitty1276
smitty1276
Actually, I didn't change a thing--to my recollection--and it works today. I don't get it.

If it exhibits that behavior again I'll check back in. For now, I'm going to assume I changed something that I can't remember.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.