Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash dev branch 'EvaluateScript' #82

Open
gaetandezeiraud opened this issue Feb 25, 2025 · 1 comment
Open

Crash dev branch 'EvaluateScript' #82

gaetandezeiraud opened this issue Feb 25, 2025 · 1 comment

Comments

@gaetandezeiraud
Copy link

gaetandezeiraud commented Feb 25, 2025

I don't know yet why. But I use the dev branch because I need a way to communicate between the WebView and the C# backend.
But I got a crash when I use EvaluateScript. Not every time, but in a regular way.

Here my method

 public override void CustomEvent(string name, object detail)
{
    string jsCode = "(function() { window.dispatchEvent(new CustomEvent('" + name + "', { detail: " + JsonSerializer.Serialize(detail) + "})); })();";
    _mainThreadDispatcher.Invoke(() => _view.EvaluateScript(jsCode, out _));
}

The object is an array of struct :

    public struct LevelUpReward
    {
        public string Id { get; set; }
        public string Img { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }

        public LevelUpReward(string id, string img, string name, string desc)
        {
            Id = id;
            Img = img;
            Name = name;
            Description = desc;
        }
    };

The code of _mainThreadDispatcher (I use monogame, I am in a game loop, so WorkLoop is call at each Update) :

public class Dispatcher
{
    private readonly ConcurrentQueue<Action> _workQueue = new ConcurrentQueue<Action>();

    public void Invoke(Action action)
    {
        _workQueue.Enqueue(action);
    }

    public void WorkOnce()
    {
        if (_workQueue.TryPeek(out var action))
        {
            action.Invoke();
            _workQueue.TryDequeue(out _); // Delete
        }
    }

    public void WorkLoop()
    {
        while (_workQueue.TryDequeue(out var action))
        {
            action.Invoke();
        }
    }

    public bool IsEmpty()
    {
        return _workQueue.IsEmpty;
    }

    public int Count => _workQueue.Count;
}

The error, I can get it by enabling all "Common Language Runtime Exceptions" inside the Exception Settings of Visual Studio.

Unable to read data from the transport connection: The I/O operation has been aborted due to a thread stop or at the request of an application.

   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken) in System.Net.Sockets\Socket.cs:line 405
@gaetandezeiraud gaetandezeiraud changed the title Crash dev branch Crash dev branch 'EvaluateScript' Feb 25, 2025
@gaetandezeiraud
Copy link
Author

I have the same code with WebView2 and it doesn't crash with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant