Web Player Data Execution Prevention

I’ve built a simple project that communicates to a socket server, and I’ve made sure the socket communication runs in a thread away from the Unity UI thread. Everything runs just fine when the app is running, and I’m closing the socket as soon as the app exits.

In the standalone projector all is well, but in any browser on Windows Vista, a few seconds after I close the project it crashes the browser with a windows Data Execution Prevention error.

Have you guys encountered anything like this before?

Sounds like an async socket and the attempt to kill it in OnApplicationQuit …

If thats the case then that won’t work I fear because the time the socket takes to close is longer than the time unity takes to shutdown … as a consequence it will backfire and crash.

if you want to use async sockets ensure that you release the socket before you attempt to shutdown or don’t use the async one

That’s exactly what I’m doing Dreamora. I guess I could use a synchronous socket in another thread, but won’t the problem still be there? Or is it something specifically with the asynchronous sockets?

I rewrote my socket client in Unity using the TcpClient class, and I’m running the Connect and Stream read in another thread.

I managed to get the web player to stop crashing by closing the socket in the OnDisable event of the script instead of OnApplicationQuit.

However, a new problem has emerged. Whenever I close the synchronous socket the Unity3d Editor crashes 100% of the time if I’m running the game preview. Has anyone seen this before? How are you guys closing sockets in your games?

I don’t use them in any parallel manner.

Async sockets have above problem.
Threads on the other end are very problematic on Mono 1.2.5 too which is used in Unity 2.x
Question is: do you really need it threading anyway, its not like the webplayer will end as server and thus require threading to work off the queue …

Thanks for the replies Dreamora,

I’m using sockets to keep a persistent connection from the server, which is handling all my game logic. Its a multiplayer game, so it seems like a better approach than requiring the client to poll a server at regular intervals. I’d like the server to send out messages to the clients, which are listening on their connections.

So the clients (Unity) aren’t going to be servers, but they need to keep their ears open for any messages from the server. That’s why I originally started out using Asynchronous sockets, and now converted them to synchronous on another thread. And since I’m using the web player, I need to account for times when a player may decide to end the game by closing the site, or navigating away. I can’t always count on the a UI activity to end the socket connection.

Does Unity have a better way of handling messages that sockets? I’m coming at this from a Flash Developer’s standpoint, where sockets are our bread and butter.