openmultiplayer / server-beta-old

open.mp server beta releases
142 stars 14 forks source link

[BUG]: TextDrawSetString server crash #40

Closed ZantetsukenGT closed 2 years ago

ZantetsukenGT commented 2 years ago

Description

Im currently using a textdraw which is never destroyed, only hidden or set text to "_" and its only purpose is to show time passed every 1000 ms and crashes when using TextDrawSetString(textdraw, text[])

How to re-produce this bug

it may be related to passing in a buffer without proper null terminator Im sharing a snippet which has an oddly sized buffer just to showcase the bug, try to play around the timer repeat values

prolly i could prevent the crash using va_return instead, this is just legacy code i happen to be maintaining and didn't crash on samp

#include <a_samp>

new Text: PauseTD;
new TotalPausesInRound; //try to play around increasing this value
new PauseTimeElapsed;
public OnGameModeInit()
{
    PauseTD = TextDrawCreate(324.000000, 390.000000, "~r~~h~~h~Round paused");
    TextDrawBackgroundColor(PauseTD, 0x00000044);
    TextDrawFont(PauseTD, 1);
    TextDrawLetterSize(PauseTD, 0.280000, 1.500000);
    TextDrawColor(PauseTD, 255);
    TextDrawSetOutline(PauseTD, 1);
    TextDrawSetProportional(PauseTD, 1);
    TextDrawAlignment(PauseTD, 2);

    TextDrawShowForAll(PauseTD);

    SetTimer("PauseStopWatch", 1000, true); //try to play around reducing interval's value to make things happen faster
}

forward PauseStopWatch();
public PauseStopWatch()
{
    PauseTimeElapsed++;
    new str[68];
    format(str, sizeof str, "~r~~h~Round is paused!~n~~w~Time: ~r~~h~%02d:%02d ~w~Count: ~r~~h~%d", PauseTimeElapsed / 60, PauseTimeElapsed % 60, TotalPausesInRound);
    TextDrawSetString(PauseTD, str);
    return 1;
}

Relevant log output

[2022-04-23T00:45:31Z] [Info] [debug] Server crashed while executing attdef.amx
[2022-04-23T00:45:31Z] [Info] [debug] AMX backtrace:
[2022-04-23T00:45:31Z] [Info] [debug] #0 native TextDrawSetString () in Pawn.so
[2022-04-23T00:45:31Z] [Info] [debug] #1 00094f84 in public PauseStopWatch () in attdef.amx
[2022-04-23T00:45:31Z] [Info] [debug] Native backtrace:
[2022-04-23T00:45:31Z] [Info] [debug] #0 f5339f7f in _Z13GetStackTraceRSt6vectorI10StackFrameSaIS0_EEPv () in plugins/crashdetect.so
[2022-04-23T00:45:31Z] [Info] [debug] #1 f533281d in _ZN11CrashDetect20PrintNativeBacktraceERSoRKN2os7ContextE () in plugins/crashdetect.so
[2022-04-23T00:45:31Z] [Info] [debug] #2 f5332e48 in _ZN11CrashDetect20PrintNativeBacktraceERKN2os7ContextE () in plugins/crashdetect.so
[2022-04-23T00:45:31Z] [Info] [debug] #3 f53345dc in _ZN11CrashDetect7OnCrashERKN2os7ContextE () in plugins/crashdetect.so
[2022-04-23T00:45:31Z] [Info] [debug] #4 f533979f in ?? () in plugins/crashdetect.so
[2022-04-23T00:45:31Z] [Info] [debug] #5 f7fcb580 in __kernel_rt_sigreturn () in linux-gate.so.1
[2022-04-23T00:45:31Z] [Info] [debug] #6 0810adbb in ?? () in ./omp-server
[2022-04-23T00:45:31Z] [Info] [debug] #7 ffcfefb9 in ?? ()
[2022-04-23T00:45:31Z] [Info] [debug] Registers:
[2022-04-23T00:45:31Z] [Info] [debug] EAX: 0810ad91 EBX: f6d77000 ECX: 0000003f EDX: ffcfccbd
[2022-04-23T00:45:31Z] [Info] [debug] ESI: 00000020 EDI: 00000000 EBP: ffcfefcc ESP: ffcfcc7c
[2022-04-23T00:45:31Z] [Info] [debug] EIP: 0810adbb EFLAGS: 00010296
[2022-04-23T00:45:31Z] [Info] [debug] Stack:
[2022-04-23T00:45:31Z] [Info] [debug] ESP+00000000: f6d3603a f787e094 083f3a2e 0000003f
[2022-04-23T00:45:31Z] [Info] [debug] ESP+00000020: 0000007e ffcf003f 000001b0 00000218
[2022-04-23T00:45:31Z] [Info] [debug] ESP+00000040: 7e727e00 527e687e 646e756f 20736920
[2022-04-23T00:45:31Z] [Info] [debug] ESP+00000060: 7e203a65 687e7e72 3a30307e 7e203130
[2022-04-23T00:45:31Z] [Info] [debug] ESP+00000080: f725c137 0a945c50 ffcfcd34 3042523e
[2022-04-23T00:45:31Z] [Info] [debug] ESP+000000a0: ffcfcdc0 0a945f44 f73e2000 09a4770c
[2022-04-23T00:45:31Z] [Info] [debug] ESP+000000c0: 00000000 00000000 00000000 ffcfbbe0
[2022-04-23T00:45:31Z] [Info] [debug] ESP+000000e0: f71e4d02 09a9cba0 ee4edf5f ffcfbbe0
[2022-04-23T00:45:31Z] [Info] [debug] ESP+00000100: ffcfbbe0 ee4edf5f 0000bbe0 61916c33
[2022-04-23T00:45:31Z] [Info] [debug] ESP+00000120: ffffbcd4 0a221c30 f7fcb3ac ffcfcdf8
[2022-04-23T00:45:31Z] [Info] [debug] ESP+00000140: ffcfcdec ef20b400 f6d77000 0000003f
[2022-04-23T00:45:31Z] [Info] [debug] ESP+00000160: 00000000 00000000 00000013 0000007e
[2022-04-23T00:45:31Z] [Info] [debug] ESP+00000180: 65737561 6e7e2164 7e777e7e 656d6954
[2022-04-23T00:45:31Z] [Info] [debug] ESP+000001a0: 756f437e 203a746e 7e7e727e 00317e68
[2022-04-23T00:45:31Z] [Info] [debug] ESP+000001c0: 084d4000 00000040 f7e64000 f7e64740
[2022-04-23T00:45:31Z] [Info] [debug] ESP+000001e0: f725c137 0833e22c f7dcbf7d 0000003f
[2022-04-23T00:45:31Z] [Info] [debug] ESP+00000200: 084d4000 f6c65bd4 0000003f 0abae230
[2022-04-23T00:45:31Z] [Info] [debug] ESP+00000220: 08116ce3 0833e22c 0833e346 f6d77000
[2022-04-23T00:45:31Z] [Info] [debug] ESP+00000240: f71e4d02 09a9cba0 d25b6aba ffcfced8
[2022-04-23T00:45:31Z] [Info] [debug] ESP+00000260: f6f22551 ffcfcf80 00000000 00000000
[2022-04-23T00:45:31Z] [Info] [debug] ESP+00000280: f6d35566 f6c65b98 f787e094 ef20b400
[2022-04-23T00:45:31Z] [Info] [debug] ESP+000002a0: 0000003f ef20b400 0000003f 303a3030
[2022-04-23T00:45:31Z] [Info] [debug] ESP+000002c0: f6f5bb19 f6c65b98 ef20b400 0000003f
[2022-04-23T00:45:31Z] [Info] [debug] ESP+000002e0: f6f5d62c f714974c f6c65b98 ffcfcf80
[2022-04-23T00:45:31Z] [Info] [debug] ESP+00000300: f6f4dd9f ef20b400 0000003f 0000003f
[2022-04-23T00:45:31Z] [Info] [debug] ESP+00000320: 00000008 f714974c f7145000 ffcfd578
[2022-04-23T00:45:31Z] [Info] [debug] ESP+00000340: 00000020 0a250fb4 00000001 00000000
[2022-04-23T00:45:31Z] [Info] [debug] ESP+00000360: 00000000 00000000 0000028d f7d008fb
[2022-04-23T00:45:31Z] [Info] [debug] ESP+00000380: 0833e247 00000007 00000005 ffcfd0d0
[2022-04-23T00:45:31Z] [Info] [debug] ESP+000003a0: 0833d8e8 00000007 00000005 ffcfd0d0
[2022-04-23T00:45:31Z] [Info] [debug] ESP+000003c0: f7259cc0 0ac39160 ffcfd1e1 00000007
[2022-04-23T00:45:31Z] [Info] [debug] ESP+000003e0: f6f4f0c9 00000002 f73e2000 f7145000
[2022-04-23T00:45:31Z] [Info] [debug] Loaded modules:
[2022-04-23T00:45:31Z] [Info] [debug] 00000000 - 004bc317 omp-server
[2022-04-23T00:45:31Z] [Info] [debug] f7fcb000 - f7fcc2d2 linux-gate.so.1
[2022-04-23T00:45:31Z] [Info] [debug] f7fb8000 - f7fbae40 /lib/i386-linux-gnu/libdl.so.2
[2022-04-23T00:45:31Z] [Info] [debug] f7f96000 - f7fb59db /lib/i386-linux-gnu/libpthread.so.0
[2022-04-23T00:45:31Z] [Info] [debug] f7f8b000 - f7f92d6f /lib/i386-linux-gnu/librt.so.1
[2022-04-23T00:45:31Z] [Info] [debug] f7e87000 - f7f89ab0 /lib/i386-linux-gnu/libm.so.6
[2022-04-23T00:45:31Z] [Info] [debug] f7e68000 - f7e84440 /lib/i386-linux-gnu/libgcc_s.so.1
[2022-04-23T00:45:31Z] [Info] [debug] f7c7f000 - f7e6d4f3 /lib/i386-linux-gnu/libc.so.6
[2022-04-23T00:45:31Z] [Info] [debug] f7fcd000 - f7ff724b /lib/ld-linux.so.2
[2022-04-23T00:45:31Z] [Info] [debug] f782a000 - f7882750 components/Pickups.so
[2022-04-23T00:45:31Z] [Info] [debug] f7646000 - f7699b98 components/Variables.so
[2022-04-23T00:45:31Z] [Info] [debug] f75bd000 - f764eda4 components/Unicode.so
[2022-04-23T00:45:31Z] [Info] [debug] f73eb000 - f75c2518 /lib/i386-linux-gnu/libstdc++.so.6
[2022-04-23T00:45:31Z] [Info] [debug] f7152000 - f74217f1 components/LegacyNetwork.so
[2022-04-23T00:45:31Z] [Info] [debug] f6e1f000 - f71ce411 components/Pawn.so
[2022-04-23T00:45:31Z] [Info] [debug] f6dc9000 - f6e23f44 components/Actors.so
[2022-04-23T00:45:31Z] [Info] [debug] f6d1d000 - f6d7cd2c components/TextDraws.so
[2022-04-23T00:45:31Z] [Info] [debug] f6bfc000 - f6c6c904 components/Vehicles.so
[2022-04-23T00:45:31Z] [Info] [debug] f6a92000 - f6aeff04 components/TextLabels.so
[2022-04-23T00:45:31Z] [Info] [debug] f69f2000 - f6a4c5f0 components/Menus.so
[2022-04-23T00:45:31Z] [Info] [debug] f69a2000 - f69f6084 components/Dialogs.so
[2022-04-23T00:45:31Z] [Info] [debug] f6957000 - f69a5e0c components/Timers.so
[2022-04-23T00:45:31Z] [Info] [debug] f6903000 - f695b4ac components/GangZones.so
[2022-04-23T00:45:31Z] [Info] [debug] f604f000 - f60c155c components/Objects.so
[2022-04-23T00:45:31Z] [Info] [debug] f5ffd000 - f6053bc8 components/Classes.so
[2022-04-23T00:45:31Z] [Info] [debug] f5e87000 - f600d538 components/Databases.so
[2022-04-23T00:45:31Z] [Info] [debug] f5d27000 - f5e94479 components/LegacyConfig.so
[2022-04-23T00:45:31Z] [Info] [debug] f5cd7000 - f5d2b240 components/Checkpoints.so
[2022-04-23T00:45:31Z] [Info] [debug] f5b64000 - f5ce73ad components/Console.so
[2022-04-23T00:45:31Z] [Info] [debug] f531a000 - f53623d4 /root/attdef/plugins/crashdetect.so
[2022-04-23T00:45:31Z] [Info] [debug] f4df9000 - f533c820 /root/attdef/plugins/requests.so
[2022-04-23T00:45:31Z] [Info] [debug] f4df0000 - f4df6ed0 /root/attdef/plugins/pawn-memory.so
[2022-04-23T00:45:31Z] [Info] [debug] f4d9c000 - f4defb7c /root/attdef/plugins/samp-precise-timers.so
[2022-04-23T00:45:31Z] [Info] [debug] f4b2d000 - f4c01b05 /root/attdef/plugins/streamer.so
[2022-04-23T00:45:31Z] [Info] [debug] f4d27000 - f4d9c838 /root/attdef/plugins/samp_bcrypt.so
[2022-04-23T00:45:31Z] [Info] [debug] f4d06000 - f4d257c0 /root/attdef/plugins/sscanf.so
[2022-04-23T00:45:31Z] [Info] [debug] ef30a000 - ef31bad0 /lib/i386-linux-gnu/libnss_files.so.2
[2022-04-23T00:45:31Z] [Info] [debug] ef303000 - ef307824 /lib/i386-linux-gnu/libnss_dns.so.2
[2022-04-23T00:45:31Z] [Info] [debug] da1bd000 - da1d457c /lib/i386-linux-gnu/libresolv.so.2

open.mp server version

*build 2

Operating system or distribution

*Debian 11 64-bit with

dpkg --add-architecture i386
apt update
apt install libc6:i386 libncurses6:i386 libstdc++6:i386

Contact information

*Zantetsuken#2220

AmyrAhmady commented 2 years ago

Are you able to reproduce this on windows too?

ZantetsukenGT commented 2 years ago

Okay look I think I know what's the issue here.

Giving a little more of context, this pause timer thing is used to freeze the players, vehicles and other timers in place to pause an attack vs defender round, maintaining the round state integrity for both teams.

The round pause can be triggered through a command, key bind or when a player in the round crashes/timeouts/gets kicked or promptly /q'd.

Players crash/quit/get kicked all the time and only managed to cause the crash when one of the players in the round disconnects and triggers the pause function.

So generally speaking i think it only crashes when one of the player is no longer online and i call the TextDrawSetString function, prolly a race condition or similar.

In short the snippet above isn't enough and will provide one later.

AmyrAhmady commented 2 years ago

Can you give it a little more test, and see if you are calling TextDrawSetString for that disconnected player as well? Shouldn't be an issue by default, but just asking, or calling TextDrawSetString and then show it in OnPlayerDisconnect when your player disconnects

ZantetsukenGT commented 2 years ago

try this snippet instead, this crashes on windows as well, but doesn't give a fancy stack trace

#include <a_samp>

main() {}

new Text: PauseTD;
new TotalPausesInRound;
new PauseTimeElapsed;

public OnPlayerDisconnect()
{
    PauseTD = TextDrawCreate(324.000000, 390.000000, "~r~~h~~h~Round paused");
    TextDrawBackgroundColor(PauseTD, 0x00000044);
    TextDrawFont(PauseTD, 1);
    TextDrawLetterSize(PauseTD, 0.280000, 1.500000);
    TextDrawColor(PauseTD, 255);
    TextDrawSetOutline(PauseTD, 1);
    TextDrawSetProportional(PauseTD, 1);
    TextDrawAlignment(PauseTD, 2);

    TextDrawShowForAll(PauseTD);

    SetTimer("PauseStopWatch", 3000, true);
    return 1;
}

forward PauseStopWatch();
public PauseStopWatch()
{
    PauseTimeElapsed++;
    new str[68];
    format(str, sizeof str, "~r~~h~Round is paused!~n~~w~Time: ~r~~h~%02d:%02d ~w~Count: ~r~~h~%d", PauseTimeElapsed / 60, PauseTimeElapsed % 60, TotalPausesInRound);
    TextDrawSetString(PauseTD, str);
    return 1;
}
ksenonadv commented 2 years ago

Fixed next build.