Thunder
#9
(05-13-2015, 06:40 AM)xoft Wrote: Due to multithreading it cannot be so simple - the "player disconnecting" will be processed by a different thread running in parallel to your plugin, so the Player object can become invalid right after the IF has checked it to be valid, but before the --code executes:
-- Player is currently connected, PlayerObj is a valid object
if (PlayerObj) then
  -- Player disconnects right here
  -- PlayerObj becomes invalid
  PlayerObj:SendMessage("...")  -- fails - PlayerObj invalid, despite the condition
end
This is the price we pay for being multithreaded - we do need to use the DoWith and ForEach calls. Those guarantee that the object is valid as long as the callback is executing (but, again, you cannot store the object to be used later after the call).

I see, what about using pcall? This way your code won't break the whole script and if it errors out anywhere in it, it can be handled? If used rarely then I can see it working fine. I know pcall is relatively slow compared to regular function calls.
Reply
Thanks given by:


Messages In This Thread
Thunder - by NiLSPACE - 05-09-2015, 09:38 PM
RE: Thunder - by worktycho - 05-09-2015, 09:46 PM
RE: Thunder - by xoft - 05-09-2015, 10:02 PM
RE: Thunder - by worktycho - 05-09-2015, 10:04 PM
RE: Thunder - by xoft - 05-09-2015, 10:08 PM
RE: Thunder - by worktycho - 05-09-2015, 10:20 PM
RE: Thunder - by Shadowraix - 05-13-2015, 06:28 AM
RE: Thunder - by xoft - 05-13-2015, 06:40 AM
RE: Thunder - by Shadowraix - 05-13-2015, 07:14 AM
RE: Thunder - by xoft - 05-13-2015, 07:32 AM
RE: Thunder - by Shadowraix - 05-13-2015, 07:35 AM



Users browsing this thread: 1 Guest(s)