A serious problem that is easily overlooked(Maybe Bug?)

Started by Yyg, Jul 31, 2022, 05:51 PM

Previous topic - Next topic

Yyg

Sorry for my poor English, but I would like to introduce a problem that has been bothering me for more than 5 years

I've written a lot of servers and tried to make the most of the VCMPAPI, which means I tried to use a lot of the API, but eventually it would crash, maybe because I wasn't using it the right way

But I've been refactoring a script recently, and I've listed the "occasional error-free crash" as the key issue. I've been struggling with this problem for a few years now(https://forum.vc-mp.org/?topic=7898.msg49014#msg49014), which led me to think it had something to do with the SQlite plugin or VCMP0.4 (yes, it does have a little bit).

It's very frustrating when you have tried your best to verify try catch and null judgments, but still occasionally crash without any errors

If your server occasionally crashes without warning, especially when onPlayerJoin or onPlayerPart (or when players are reconnecting), check your server for this dangerous code!!
function onPlayerJoin (player)
{
player.Colour = RGB(205, 186, 150);
}

Did something happen? Of course not :(

But if you're like me, and consider it a variable to avoid the hassle of having to change colors in batches later, there's a reasonable chance that the server will crash without warning when a player enters or exits

local testColor = RGB(255, 255, 255);
function onPlayerJoin (player)
{
player.Colour = testColor;
}

What's going to happen? Not necessarily, it will still work, you will change the player's color, but after hundreds of tests, it is this dangerous line of code that is causing the problem

How to reproduce almost 100 percent?
Try building a test script that only places this line of code (the way you use variables, whether it's local var = RGB() \ var <- RGB())
When you exit (reconnect) the server, there is a chance that you will cause the server to crash

However, if you click on your server. Exe with the mouse after the player has successfully entered the server (in this case, he will lose response and stop partial synchronization), wait for a few seconds, then click Reconnect of the game, and you will find that you can explore the server, but you can't join in correctly. You let go of the server. Exe mouse, at this point you should be prompted to be kicked out of the game (if not, please repeat the previous steps to try)

If YOU HAVE BEEN KICKED OUT OF THE GAME, try/CONNECT 127.0.0.1 8192 (or reconnect), BY this TIME YOUR server SHOULD have crashed

It looks like player.colour is very strict, you can only go straight to RGB(255, 255, 255)
It can be seen that if you try to set player.colour = null then you will crash directly

As for the impact of SQLite or VCMP0.4 I mentioned earlier, it may be due to a short delay, similar to achieving a "mouse click exe" effect, but that's not their problem, it's the code

This may or may not be a BUG, but I'm sure there will be people using variables as RGB, you can try to check if there is a problem, even if it is not in onPlayerJoin