YSI-Includes icon indicating copy to clipboard operation
YSI-Includes copied to clipboard

[y_inline] Conflit with a_mysql_yinline (?)

Open C-far opened this issue 7 years ago • 20 comments

The logs :

[11:56:17] Commands_OnPlayerCommandText called: 0 /info account t
[11:56:17] HashMap_Get called: mask = 2710731 (203)
[11:56:17] Commands_OnPlayerCommandText: info, 6, 2710731, 13
[11:56:17] Commands_OnPlayerCommandText: Use 1
[11:56:17] Commands_OnPlayerCommandText: Read 13
[11:56:17] Commands_OnPlayerCommandText: Master 1 2
[11:56:17] Commands_OnPlayerCommandText: Local
[11:56:17] Callback_Get called: CMD_InfoAccountX°h
[11:56:17] Malloc_Allocate called: 302, 77, 725893, 2
[11:56:17] Malloc_Allocate: heap = 20029484
[11:56:17] local: 296, params: 3, stack: 302, a: 0
[11:56:17] Command_ReProces: Result = 1 2 1

[11:56:25] Malloc_Allocate called: 2, 77, 725893, 2
[11:56:25] Malloc_Allocate: heap = 20030760
[11:56:25] Callback_Get called: StartingVehicle¤üð
[11:56:25] Malloc_Allocate called: 7, 88, 725893, 100
[11:56:25] Malloc_Allocate: heap = 20030700
[11:56:25] local: 1, params: 3, stack: 7, a: 88
[11:56:25] Callback_Get end
[11:56:28] Malloc_Free called: 88328
[11:56:28] Malloc_Free: size = 0
[11:56:28] Malloc_Free called: 77
[11:56:28] Malloc_Free: size = 2

[11:59:35] Malloc_Allocate called: 2, 77, 725893, 2
[11:59:35] Malloc_Allocate: heap = 20030760
[11:59:35] Callback_Get called: StartingVehicle¤üð
[11:59:35] Malloc_Allocate called: 7, 96, 725893, 92
[11:59:35] Malloc_Allocate: heap = 20030700
[11:59:35] local: 1, params: 3, stack: 7, a: 96
[11:59:35] Callback_Get end
[11:59:37] Malloc_Free called: 88360
[11:59:37] Malloc_Free: size = 0
[11:59:37] Malloc_Free called: 77
[11:59:37] Malloc_Free: size = 2

[11:59:40] Commands_OnPlayerCommandText called: 0 /info account t
[11:59:40] HashMap_Get called: mask = 2710731 (203)
[11:59:40] Commands_OnPlayerCommandText: info, 6, 2710731, 13
[11:59:40] Commands_OnPlayerCommandText: Use 1
[11:59:40] Commands_OnPlayerCommandText: Read 13
[11:59:40] Commands_OnPlayerCommandText: Master 1 2
[11:59:40] Commands_OnPlayerCommandText: Local
[11:59:40] Callback_Get called: CMD_InfoAccountX°h
[11:59:40] Malloc_Allocate called: 302, 77, 725893, 2
[11:59:40] Malloc_Allocate: heap = 20029484
[11:59:40] local: 296, params: 3, stack: 302, a: 0
[11:59:40] Command_ReProces: Result = 1 2 1

[11:59:44] Commands_OnPlayerCommandText called: 0 /info account c
[11:59:44] HashMap_Get called: mask = 2710731 (203)
[11:59:44] Commands_OnPlayerCommandText: info, 6, 2710731, 13
[11:59:44] Commands_OnPlayerCommandText: Use 1
[11:59:44] Commands_OnPlayerCommandText: Read 13
[11:59:44] Commands_OnPlayerCommandText: Master 1 2
[11:59:44] Commands_OnPlayerCommandText: Local
[11:59:44] Callback_Get called: CMD_InfoAccountX°h
[11:59:44] Malloc_Allocate called: 302, 77, 725893, 2
[11:59:44] Malloc_Allocate: heap = 20029484
[11:59:44] local: 296, params: 3, stack: 302, a: 0
[11:59:44] Command_ReProces: Result = 1 2 1

[12:37:12] Commands_OnPlayerCommandText called: 0 /info
[12:37:12] HashMap_Get called: mask = 2710731 (203)
[12:37:12] Commands_OnPlayerCommandText: info, 5, 2710731, 13
[12:37:12] Commands_OnPlayerCommandText: Use 1
[12:37:12] Commands_OnPlayerCommandText: Read 13
[12:37:12] Commands_OnPlayerCommandText: Master 1 2
[12:37:12] Commands_OnPlayerCommandText: Local
[12:37:12] Command_ReProces: Result = 1 2 1

[12:37:15] Commands_OnPlayerCommandText called: 0 /info char c
[12:37:15] HashMap_Get called: mask = 2710731 (203)
[12:37:15] Commands_OnPlayerCommandText: info, 6, 2710731, 13
[12:37:15] Commands_OnPlayerCommandText: Use 1
[12:37:15] Commands_OnPlayerCommandText: Read 13
[12:37:15] Commands_OnPlayerCommandText: Master 1 2
[12:37:15] Commands_OnPlayerCommandText: Local
[12:37:15] Callback_Get called: CMD_InfoCharacterà8
[12:37:15] Malloc_Allocate called: 174, 77, 725893, 2
[12:37:15] Malloc_Allocate: heap = 20029996
[12:37:15] local: 168, params: 3, stack: 174, a: 0
[12:37:15] Command_ReProces: Result = 1 2 1

[12:37:36] Malloc_Allocate called: 2, 77, 725893, 2
[12:37:36] Malloc_Allocate: heap = 20030760
[12:37:36] Callback_Get called: StartingVehicle¤üð
[12:37:36] Malloc_Allocate called: 7, 104, 725893, 84
[12:37:36] Malloc_Allocate: heap = 20030700
[12:37:36] local: 1, params: 3, stack: 7, a: 104
[12:37:36] Callback_Get end
[12:37:38] Malloc_Free called: 88392
[12:37:38] Malloc_Free: size = 0
[12:37:38] Malloc_Free called: 77
[12:37:38] Malloc_Free: size = 2

[12:37:50] Callback_Get called: AS_InfoLChar|Ô
[12:37:50] Malloc_Allocate called: 73, 77, 725893, 2
[12:37:50] Malloc_Allocate: heap = 20029736
[12:37:50] local: 66, params: 4, stack: 73, a: 112
[12:37:50] Callback_Get end

[12:37:50] Callback_Get called: LoadVehiclesChar¬H
[12:37:50] Malloc_Allocate called: 1184, 77, 725893, 2
[12:37:50] Malloc_Allocate: heap = 20025668
[12:37:50] local: 1178, params: 3, stack: 1184, a: 0
[12:37:50] Malloc_Free called: 112
[12:37:50] Malloc_Free: size = 73

The callback CMD_InfoAccount isn't called and the callback StartingVehicle is perfectly called here, but sometimes it's not called and I have to restart the server. After, I tested another system and the callback AS_InfoLChar is perfectly called but LoadVehiclesChar is not called.

I uncommented the line 414 and I put the variable a in the printf (you can see it in the logs).

This bug is totally random, it doesn't appear to the start as you see :

[12:48:48] Commands_OnPlayerCommandText called: 0 /info account c
[12:48:48] HashMap_Get called: mask = 2710731 (203)
[12:48:48] Commands_OnPlayerCommandText: info, 6, 2710731, 13
[12:48:48] Commands_OnPlayerCommandText: Use 1
[12:48:48] Commands_OnPlayerCommandText: Read 13
[12:48:48] Commands_OnPlayerCommandText: Master 1 2
[12:48:48] Commands_OnPlayerCommandText: Local
[12:48:48] Inline_Entry called: CMD_InfoAccount:....
[12:48:48] AMX_Write called: 560464, 2
[12:48:48] AMX_Write called: 560468, 548952
[12:48:48] AMX_Write called: 560472, 75779
[12:48:48] AMX_Write called: 560480, 2949616
[12:48:48] Inline_Allocator called
[12:48:48] Inline_Main called (1)
[12:48:48] Inline_Main: YSI_g_sCurInlineEntry = 86058
[12:48:48] Inline_Main: YSI_g_sCurInlineLoop = 860A0
[12:48:48] Inline_Main: YSI_g_sCurInlineCode = 860F8
[12:48:48] Inline_Main: varCount = 0
[12:48:48] Inline_Main: arrCount = 0
[12:48:48] Inline_Main: strCount = 0
[12:48:48] Inline_Main: TYPE 0
[12:48:48] AMX_Write called: -281912, -205604276
[12:48:48] AMX_Write called: 560476, 549040
[12:48:48] AMX_Write called: 560464, 2
[12:48:48] Callback_Get called: CMD_InfoAccountX°ð
[12:48:48] Malloc_Allocate called: 302, 725894, 725893, 2
[12:48:48] Malloc_Allocate: heap = 20029484
[12:48:48] local: 296, params: 3, stack: 302, a: 725903
[12:48:48] Callback_Get end
[12:48:48] Command_ReProces: Result = 1 2 1
[12:48:48] Malloc_Free called: 725903
[12:48:48] Malloc_Free: size = 302

[12:49:24] Commands_OnPlayerCommandText called: 0 /info account c
[12:49:24] HashMap_Get called: mask = 2710731 (203)
[12:49:24] Commands_OnPlayerCommandText: info, 6, 2710731, 13
[12:49:24] Commands_OnPlayerCommandText: Use 1
[12:49:24] Commands_OnPlayerCommandText: Read 13
[12:49:24] Commands_OnPlayerCommandText: Master 1 2
[12:49:24] Commands_OnPlayerCommandText: Local
[12:49:24] Callback_Get called: CMD_InfoAccountX°ð
[12:49:24] Malloc_Allocate called: 302, 725894, 725893, 2
[12:49:24] Malloc_Allocate: heap = 20029484
[12:49:24] local: 296, params: 3, stack: 302, a: 725903
[12:49:24] Callback_Get end
[12:49:24] Command_ReProces: Result = 1 2 1
[12:49:24] Malloc_Free called: 725903
[12:49:24] Malloc_Free: size = 302

Here is the code for CMD_InfoAccount (I use the latest version of YSI and of a_mysql_yinline) :

new
    query[256];

mysql_format(db, query, sizeof(query), "SELECT * FROM `ACCOUNTS` WHERE USERNAME LIKE '%%%e%%'", name);
inline CMD_InfoAccount() {
    new
        rows = cache_num_rows();
    
    if(rows) {
        if(rows > 30) {
            Sce(playerid, "Soyez plus précis dans le nom, plus de 30 comptes (%d) ont été trouvés.", rows);
        } else {
            accInfo[playerid][E_ACC_CACHE_LIST_FULLNAME] = cache_save();

            new
                info[30 * MAX_PLAYER_NAME];

            for(new i = 0; i < rows; i++) {
                cache_get_value(i, "USERNAME", name);
                strcat(info, name);
                strcat(info, "\n");
            }
            Dialog_Show(playerid, CMD_InfoAccount, DIALOG_STYLE_LIST, "Infos: Account", info, "O", "X");
        }
    } else {
        Sce(playerid, "Aucun compte trouvé.");
    }
}
mysql_tquery_inline(db, query, using inline CMD_InfoAccount);

C-far avatar Aug 17 '18 11:08 C-far

Can you try the inline MySQL function from YSI_Extra?

Y-Less avatar Aug 17 '18 12:08 Y-Less

There is no inline MySQL function in YSI_Extra, no ?

C-far avatar Aug 17 '18 12:08 C-far

Sorry, it is in y_inline_extra, which means it is included by default:

https://github.com/pawn-lang/YSI-Includes/blob/5.x/YSI_Coding/y_inline/y_inline_extra.inc

Y-Less avatar Aug 17 '18 12:08 Y-Less

Ah, when I said I was using the latest version, I was thinking about YSI 4 So, I'm going to move my scripts to YSI 5.x and I'll tell you if I have a bug.

C-far avatar Aug 17 '18 15:08 C-far

There is any rule to use MySQL_TQueryInline in OnGameModeInit/OnScriptInit ? Because the function doesn't call the callback :

GameMode::Init() {
    print("gamemode business");

    inline LoadBusiness() {
        new
            rows = cache_num_rows();

        printf("loadbusiness | %d", rows);
        
        for(new businessid = 0; businessid < rows; businessid++) {
            new 
                bus[E_BUSINESS_INFO],
                bool:active;
            
            cache_get_value_bool(businessid, "ACTIVE", active);

            if(active) {
                cache_get_value(businessid, "NAME", bus[E_BUS_NAME]);
                cache_get_value_int(businessid, "OWNER_CHARID", bus[E_BUS_OWNER_CHAR_DBID]);
                cache_get_value_int(businessid, "TYPE", _:bus[E_BUS_TYPE]);
                cache_get_value_int(businessid, "PRICE", bus[E_BUS_PRICE]);
                cache_get_value_int(businessid, "BANK_ACCOUNTID", bus[E_BUS_BANK_ACCOUNTID]);
                cache_get_value_int(businessid, "INTERIORID", bus[E_BUS_INTERIORID]);
                cache_get_value_bool(businessid, "HAS_PICKUP", bus[E_BUS_HAS_PICKUP]);
                cache_get_value_float(businessid, "ENTRANCE_X", bus[E_BUS_ENTRANCE_X]);
                cache_get_value_float(businessid, "ENTRANCE_Y", bus[E_BUS_ENTRANCE_Y]);
                cache_get_value_float(businessid, "ENTRANCE_Z", bus[E_BUS_ENTRANCE_Z]);
                cache_get_value_float(businessid, "EXIT_X", bus[E_BUS_EXIT_X]);
                cache_get_value_float(businessid, "EXIT_Y", bus[E_BUS_EXIT_Y]);
                cache_get_value_float(businessid, "EXIT_Z", bus[E_BUS_EXIT_Z]);
                cache_get_value_float(businessid, "SELECTOR_X", bus[E_BUS_SELECTOR_X]);
                cache_get_value_float(businessid, "SELECTOR_Y", bus[E_BUS_SELECTOR_Y]);
                cache_get_value_float(businessid, "SELECTOR_Z", bus[E_BUS_SELECTOR_Z]);

                bus[E_BUS_SELECTOR] = CreateDynamicObject(MODELID_SELECT_BUSINESS, bus[E_BUS_SELECTOR_X], bus[E_BUS_SELECTOR_Y], bus[E_BUS_SELECTOR_Z], 0.0, 0.0, 0.0, 0, 0);
                Streamer_SetIntData(STREAMER_TYPE_OBJECT, bus[E_BUS_SELECTOR], E_STREAMER_EXTRA_ID, businessid);

                if(bus[E_BUS_HAS_PICKUP]) {
                    bus[E_BUS_PICKUP_ENTRANCE] = CreateDynamicPickup(MODELID_PICKUP_BUSINESS, 1, bus[E_BUS_ENTRANCE_X], bus[E_BUS_ENTRANCE_Y], bus[E_BUS_ENTRANCE_Z], 0);
                }

                busInfo[businessid] = bus;
                Iter_Add(Business, businessid);
            }
        }
    }
    MySQL_TQueryInline(db, using inline LoadBusiness, "SELECT * FROM BUSINESS");

    return true;
}

C-far avatar Aug 17 '18 17:08 C-far

Yes, someone else just mentioned an issue with inlines in those callbacks the other day. There shouldn't be one - but clearly there is, so I'll have to look in to it.

Y-Less avatar Aug 17 '18 18:08 Y-Less

Ok for the moment I'm using a timer of 1000ms

C-far avatar Aug 17 '18 19:08 C-far

A nice trick is a timer of 0ms - it will be executed as soon as possible after the current callback ends.

Y-Less avatar Aug 17 '18 19:08 Y-Less

Ah nice trick, I didn't know that !

C-far avatar Aug 17 '18 19:08 C-far

It's possible to get the inline_return in the inline function of MySQL_TQueryInline ?

C-far avatar Aug 18 '18 08:08 C-far

Yes. That should have been done already, my bad. Of course, it only makes sense if the caller expects a return value, which I didn't know MySQL did, but I'm also not an expert on that.

Y-Less avatar Aug 18 '18 11:08 Y-Less

Done:

https://github.com/Y-Less/indirection/commit/722308dccb9c473ea15f16e272b9a4c9c7329c6d

Y-Less avatar Aug 18 '18 11:08 Y-Less

It's possible to get this value in the MySQL_TQueryInline implementation ?

C-far avatar Aug 18 '18 11:08 C-far

I'm not sure what you mean? You can't return data from a callback to the place that initiated the query, because that was done in the past.

Y-Less avatar Aug 18 '18 11:08 Y-Less

Yes that's what I was thinking. There's no way it's gonna print 5 ? :

new
    myVar = 0;

inline AnInlineFunction() {
    myVar = 5;
}
MySQL_TQueryInline(db, using inline AnInlineFunction, "a query");

printf("%d", myVar);

C-far avatar Aug 18 '18 11:08 C-far

No, the inline function happens in the future.

Southclaws avatar Aug 18 '18 12:08 Southclaws

And this was not an issue introduced in the new version, it is a fundamental restriction of threaded queries.

Y-Less avatar Aug 18 '18 16:08 Y-Less

Ok, try this, as I was reminded in another issue:

https://github.com/pawn-lang/YSI-Includes/blob/5.x/YSI_Coding/y_malloc/faqs.md

Y-Less avatar Aug 19 '18 11:08 Y-Less

For the moment no issue with YSI 5.x

C-far avatar Aug 19 '18 11:08 C-far

All, that's good.

Y-Less avatar Aug 19 '18 11:08 Y-Less