IS4Code / PawnPlus

A SA-MP plugin enhancing the capabilities of the Pawn programming language
MIT License
102 stars 17 forks source link

Other hooks not called when task in OnPlayerConnect hook #9

Closed KoertLichtendonk closed 5 years ago

KoertLichtendonk commented 5 years ago

Hey there, so I ran into another problem. I have a modular gamemode and work with a lot of hooks. Normally I do not run into problems with this, but found that when I indirectly add a task to a OnPlayerConnect hook through a callback (which from what I understand from your documentation should pause that particular callback and not OnPlayerConnect), the code from other hooks are no longer being executed.

However, if I move the code from another hook into this hook, it will.

And if I get rid of the PawnPlus task, then other hooks get called fine.

Here is an example code. I use y_hooks for hooking and include y_hooks in each include that uses it as well (as you should).

hook OnPlayerConnect(playerid)
{
    CallLocalFunction(#welcomePlayer, "d", playerid);
    return 1;
}

forward welcomePlayer(playerid);
public welcomePlayer(playerid)
{
    wait_ms(2000);
    return 1;
}

This code in another hook (in another file) doesn't get executed while it should.

#include <YSI\y_hooks>

hook OnPlayerConnect(playerid)
{
    TogglePlayerSpectating(playerid, 1);
    PlayAudioStreamForPlayer(playerid, "http://127.0.0.1/alrp/serverintro.mp3");
    switch(random(2))
    {
        case 0: // Angel Pine North Gas Station
        {
            SetPlayerPos(playerid, -1508.2727, -2991.9058, 0.0);
            SetPlayerCameraPos(playerid, -1508.2727, -2991.9058, 93.6866);
            SetPlayerCameraLookAt(playerid, -1508.5916, -2990.9526, 93.5015);
            InterpolateCameraPos(playerid, -1508.2727, -2991.9058, 93.6866, -1717.8026, -2789.3159, 121.2620, 60000, CAMERA_MOVE);
            InterpolateCameraLookAt(playerid, -1508.5916, -2990.9526, 93.5015, -1716.9001, -2788.8755, 120.8320, 60000, CAMERA_MOVE);
        }
        case 1: // Flint County Farm
        {
            SetPlayerPos(playerid, -269.4498, -1614.9242, 0.0);
            SetPlayerCameraPos(playerid, -269.4498, -1614.9242, 58.0998);
            SetPlayerCameraLookAt(playerid, -270.2507, -1614.3184, 57.8497);
            InterpolateCameraPos(playerid, -269.4498, -1614.9242, 58.0998, -255.4192, -1487.0031, 50.0984, 60000, CAMERA_MOVE);
            InterpolateCameraLookAt(playerid, -270.2507, -1614.3184, 57.8497, -256.3769, -1486.7010, 50.0233, 60000, CAMERA_MOVE);
        }
    }
    return 1;
}
IS4Code commented 5 years ago

Hi, thanks for reporting this! This is indeed incorrect; CallLocalFunction should create a new context, so no pauses inside should affect outer code. I shall look into this.

IS4Code commented 5 years ago

I can't reproduce it. For some reason, I am not able to hook a callback multiple times. If I use public instead of the second hook, it works with no issues. Can you please make me a small sample AMX that reproduces this behaviour?

Edit: I was able to get multiple hooks to work, but it still works as expected:

#include "..\include\YSI\y_hooks"

hook OnFilterScriptInit()
{
    print("from hook A");
    CallLocalFunction(#testctx, "");
}

forward testctx();
public testctx()
{
    print("from ctx");
    wait_ms(2000);
    print("from ctx 2");
    return 1;
}

#include "..\include\YSI\y_hooks"

hook OnFilterScriptInit()
{
    print("from hook B");
}

public OnFilterScriptInit()
{
    print("from callback");
}
from hook A
from ctx
from hook B
from callback

from ctx 2

What version of PawnPlus are you using?

KoertLichtendonk commented 5 years ago

I use sampctl so I should be having the latest version of everything, although in my test environment I might have some older versions. I also figured out something interesting while creating the test environment which is why it took some time for me to post this comment, when getting rid of all includes other than PawnPlus in blank.pwn, the test environment works fine, but if you add back the other includes it stops working. Which is odd, because when you remove wait_ms (or any other task in the same place) but keep all includes, it also works fine.

So yeah, maybe a conflict with another include or something? I have absolutely no clue, Compiler is not giving any errors or warnings and neither does crashdetect.

So I included everything I use. Couldn't upload it on github due to the size so I just dumped it on pCloud. https://my.pcloud.com/publink/show?code=XZjOde7ZUnUGJRezoMbYyT98SL4ukYHEwcgV

IS4Code commented 5 years ago

Your example works. I am switched to spectator and the audio stream is played (and after 2 s, "welcomePlayer called"). What shall I modify to see the issue?

KoertLichtendonk commented 5 years ago

Well, that makes it even more odd, because the same script does not appear to work for me. It only gives me the chat message after 2 seconds, but skips the other hook putting me in spectator mode and playing the stream. I can't do more tests on my side right now, but I'll do some when I get home tonight. Meanwhile, could you test it once more? I recall while testing yesterday that it worked fine a few times, thought it may have been because of me not including the other includes. Also, it probably wouldn't matter with PawnPlus, but are you testing it on 0.3.7 or 0.3.DL? I personally use 0.3.DL.

IS4Code commented 5 years ago

I have tested it on 0.3.7, but I'll try 0.3.DL when I get to it. I would be really surprised if PawnPlus was affected by the version (since it only works with the AMX API). It might be caused by another plugin altogether (YSF maybe?).

Edit: Tested on 0.3.DL; works as well. Now it even starts interpolating the camera, which it didn't on 0.3.7, for some reason. I am using the files exactly as you sent me, with the 0.3.DL binary. Try removing the other includes and plugins one by one, to see if you can track down the one that might be causing the issues.

KoertLichtendonk commented 5 years ago

For whatever reason it seems to work fine after I get rid of the a_mysql_inline include? It could also be y_inline seeing as a_mysql_inline includes y_inline as well.

Edit: Yup, it seems to be y_inline. If I comment out a_mysql_inline but leave y_inline in it also stops working.

Edit 2: It seems to be restricted to y_inline as far as I can tell. If I comment y_inline and leave y_hooks it works fine.

Edit 3: Getting this error after I include y_iterate: P:\Persoonlijk\Projects\alrpModular\dependencies\PawnPlus\pawno\include\PawnPlus.inc:890 (warning) redefinition of constant/macro (symbol "yield%9 %0;")

or if I include y_iterate after PawnPlus, this is the source P:\Persoonlijk\Projects\alrpModular\dependencies\YSI-Includes\YSI_Data\y_foreach\yield.inc:5 (warning) redefinition of constant/macro (symbol "yield%0 %1;")

EDIT 4: Getting rid of #define PP_SYNTAX doesn't seem to fix my particular problem, though.

EDIT 5: So it seems to start the audio stream, added a few prints to the second hook and they're being called, for some reason the camera's still didn't work, but now I added wait_ticks(1); in the beginning of the second hook and it seems to work without any problems. There has to be some kind of problem somewhere, either with this plugin, y_inline or an incompatibility between YSI and PP, seeing as it works fine without if I get rid of the task in welcomePlayer OR get rid of y_inline but I have no clue what it would be and it's not giving any errors either so yeah, can't do much about it other than this solution for now.

IS4Code commented 5 years ago

Does the issue persist in v0.10?

KoertLichtendonk commented 5 years ago

Oh damn, I completely forgot to try this during the weekend. I'll try to test it tonight.

KoertLichtendonk commented 5 years ago

I finally got around to testing it and the issue is still there. Personally I managed to work around my way around the problem and it's no longer really an issue for me, although if you want to keep the issue open that's fine and I'll happily keep testing it for you, but strangely so far it seems like the issue is only happening to me.

IS4Code commented 5 years ago

Alright, since I cannot reproduce this, and you seem to have got around it, I will close this. Thanks for reporting!