pawn-lang / YSI-Includes

Just the YSI include files, none of the extra stuff.
211 stars 105 forks source link

Server freezing after Alloc:Malloc_Allocate - y_dialogs #566

Open bruunotrindade opened 2 years ago

bruunotrindade commented 2 years ago

After some time using y_dialogs, my server started to freeze and I found by crash detect that it was caused by Malloc_Allocate called by y_dialogs.

Crash detect stacktrace:

[06/01/2022 17:32:46] Long callback execution detected (hang or performance issue)
[06/01/2022 17:32:46] AMX backtrace:
[06/01/2022 17:32:46] #0 0004dd04 in Alloc:Malloc_Allocate (size=159, bool:clear=false) at D:\Server\dependencies\YSI-Includes\YSI_Coding\y_timers\..\y_malloc\y_malloc_funcs.inc:824
[06/01/2022 17:32:46] #1 0005688c in Inline_UI_ (&header=@031c2dd0 24797104) at D:\Server\dependencies\YSI-Includes\YSI_Visual\y_dialog\..\..\YSI_Coding\y_inline\y_inline_impl2.inc:1948
[06/01/2022 17:32:46] #2 0024bae0 in public cmd_destroy (52, 51916996) at systems/server/jails.pwn:138
[06/01/2022 17:32:46] #3 native CallLocalFunction () in samp03svr
[06/01/2022 17:32:46] #4 00057cf8 in FIXES_OnPlayerCommandText (52, 35139780)  at D:\Server\dependencies\zcmd\zcmd.inc:104
[06/01/2022 17:32:46] #5 0000cbbc in public OnPlayerCommandText (52, 35139780) at D:\Server\dependencies\sa-mp-fixes\fixes.inc:10029

This problem was also mentioned in one comment in this issue: https://github.com/pawn-lang/YSI-Includes/issues/564

Does anyone know any solution to keep using y_dialogs? My solution was back to normal dialogs.

r4sheed commented 2 years ago

Already reported at https://github.com/pawn-lang/YSI-Includes/issues/564 I hope it will be fixed soon.

Y-Less commented 2 years ago

I've put YSI_NO_HEAP_MALLOC back in. That was always the vastly more stable method.

Y-Less commented 2 years ago

I also just discovered that the default slop space (space reserved in the heap for callback parameters) was very small (only ~256 bytes (just 64 cells)), which will be blown with any reasonable string. So the other thing to try is:

#define YSI_DEFAULT_MALLOC (2047)
#define YSI_YES_HEAP_MALLOC

That should work with the old and new versions. And I just increased the default to this anyway.

Edit: I think the comments were misleading even me and it was 256 cells, not 256 bytes. Still not a huge amount, but does mean that 2047 can probably come down to something more reasonable like 511.

Y-Less commented 2 years ago

Basically, the new version uses the heap, but the VM clears the heap at the end of every top-level callback (easy way to ensure consistency). So every time a new callback is called its reference parameters (i.e. arrays and strings) are inserted at the start of the heap, which clobbers the old malloc values that were there. To combat this I just allocate a block at the start of the malloc memory and abandon it, leaving it free to be used by different callback parameters. I just think there wasn't enough space here for large parameters. There's also code injected in to every public function to restore the previous malloc heap locations.