StormHub / NetUV

.Net standard/Core binding for Libuv
Other
76 stars 20 forks source link

Cause NullReferenceException in EventLoop #47

Closed Norgerman closed 7 years ago

Norgerman commented 7 years ago

RunLoop is called later than Schedule(sometimes maybe), and then will cause a NullReferenceException

Norgerman commented 7 years ago

pr #46

StormHub commented 7 years ago

Hi, do you have full stack trace for this?

StormHub commented 7 years ago

I believe it might be a better option to just do the schedule, then wait for the loop to start and process. e.g. wait for the loop in a run state where it is guaranteed not to be null.

StormHub commented 7 years ago

Let me change it a bit and let you to have a look at it.

Norgerman commented 7 years ago

the error's stack trace,just use the loopthread example

Loop thread error System.NullReferenceException: Object reference not set to an instance of an object.
   at NetUV.Core.Channels.EventLoop.Schedule(Action`1 action) in C:\Users\XXX\Desktop\NetUV\src\NetUV.Core\Channels\EventLoop.cs:line 94
   at LoopThread.Program.Main(String[] args) in C:\Users\XXX\Desktop\NetUV\examples\LoopThread\Program.cs:line 31.

line 94:

this.asyncHandle.Send();
StormHub commented 7 years ago

I see, thanks.

StormHub commented 7 years ago

Well, the intention is that await RunLoopAsync(); then call eventLoop.Schedule

I will fix the example.

Norgerman commented 7 years ago

The code shows that await RunLoopAsync(); will block util the loop is closed,so eventLoop.Schedule will not be called properly....

StormHub commented 7 years ago

There are a few places need to be guarded properly. Let me change it first.

StormHub commented 7 years ago

The EventLoop class is kind of experimental, forget to put some attribute on it.

Norgerman commented 7 years ago

:smile:

StormHub commented 7 years ago

48, try it out.

Norgerman commented 7 years ago

works~ 👍

StormHub commented 7 years ago

PR #48