Giter Club home page Giter Club logo

enet.managed's Issues

[BUG?] Unable to access ENetHost.PeerList

Unable to access ENetHost.PeerList

if you try to access ENetHost.PeerList it'll cause a crash.
I've tried to filter out non connected peers, yet still causes a crash.
it works for the first few peers i don't have any numbers though.

Sample code:

ManagedENet.Startup();

var ip = IPEndPoint.Parse("127.0.0.1:27015");
var _host = new ENetHost(ip, 1024, 10);
            
_host.ChecksumWithCRC32();
_host.CompressWithRangeCoder();

while (true)
{
    var ev = _host.Service(TimeSpan.FromSeconds(1));

    switch (ev.Type)
    {
         // Do stuff...
    }

    foreach (var peer in _host.PeerList.Where(s => s.State == ENetPeerState.Connected)) // Crash
    {
        // Handle pump data onto peers
    }
}

Exception:

Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at ENet.Managed.ENetPeer.get_State()
   at Sample.Program+<>c.<Main>b__0_0(ENet.Managed.ENetPeer)
   at System.Linq.Enumerable+WhereEnumerableIterator`1[[ENet.Managed.ENetPeer, ENet.Managed, Version=4.2.5.0, Culture=neutral, PublicKeyToken=null]].MoveNext()
   at Sample.Program.Main(System.String[])

Details

Version: 4.2.5
.NET Version: .NET Core 3.1
OS: Windows 10 2004 x86_64

trying this on linux

Hello im trying to use this on linux and im getting this error while trying to connect

Segmentation fault (core dumped) while in windows it work any idea?

ENetAsyncHost stops immediately after starting

ENetAsyncHost stops immediately after it's started. I believe the problem is in ENetAsyncHost.RunServiceLoop:

private void RunServiceLoop()
{
var serviceTimeout = TimeSpan.FromMilliseconds(SERVICE_TIMEOUT_MS);
while (m_Stop != false)
{
Thread.Yield();
using (var lockguard = SharedStateLock.Acquire())
{
var host = lockguard.SharedState.Host;
var @event = host.Service(serviceTimeout);
if (@event.Type == ENetEventType.None)
continue;
HandleEvent(lockguard.SharedState, @event);
while (true)
{
@event = host.CheckEvents();
if (@event.Type != ENetEventType.None)
HandleEvent(lockguard.SharedState, @event);
else
break;
}
}
}
}

The condition in the outer while loop should be !m_Stop because m_Stop != false is only true when m_Stop is true, so when the host is shutting down, which means the service thread stops immediately.

I can prove my hypothesis by manually setting m_Stop to true with some hacky reflection at runtime before starting the host:

var field = typeof(ENetAsyncHost).GetField("m_Stop", BindingFlags.NonPublic | BindingFlags.Instance);
field.SetValue(myAsyncHost, true);

[Question] Thread safety.

Is this wrapper of ENet thread-safe as I make use of its StartServiceThread function which basically explains what I am talking about.

Do I need any further code to deal with thread safety or did the wrapper have it included/implemented?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.