AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Transaction Handle wiped for no reason (https://forums.alliedmods.net/showthread.php?t=291470)

Potato Uno 12-11-2016 14:07

Transaction Handle wiped for no reason
 
Minimal test case code:

PHP Code:

    Transaction Txn SQL_CreateTransaction();
    
PrintToChatAll("(1) Transaction Handle: %d"Txn); // fine here
    
    
int AttributeIDs[15]; // Txn is never referenced here
    
int TotalAttribs TF2Attrib_ListDefIndices(WeaponEntityAttributeIDs); // Txn is never referenced here
    
PrintToChatAll("(2) Transaction Handle: %d"Txn); // ...and suddenly Txn is INVALID_HANDLE. WTF? 

Chat printout:

Code:

(1) Transaction Handle: 234029374
(2) Transaction Handle: 0

Logs:

Code:

L 12/11/2016 - 13:54:25: [SM] Exception reported: Invalid handle 0 (error 4)
L 12/11/2016 - 13:54:25: [SM] Blaming: mvm_dropped_weapons.smx
L 12/11/2016 - 13:54:25: [SM] Call stack trace:
L 12/11/2016 - 13:54:25: [SM]  [0] SQL_AddQuery
L 12/11/2016 - 13:54:25: [SM]  [1] Line 519, E:\Servers\Management Tools\Sourcemod Plugins\mvm_dropped_weapons.sp::AddPickedUpWeaponToDatabase
L 12/11/2016 - 13:54:25: [SM]  [2] Line 426, E:\Servers\Management Tools\Sourcemod Plugins\mvm_dropped_weapons.sp::RefineDroppedWeapon

sm_dump_handles showed that the transaction handle still is floating somewhere which suggests this is some memory leak?

Code:

0x0df3013e        mvm_dropped_weapons        Transaction                -1        // Incidentally, 0x0df3013e        (hex) = 234029374 (decimal)
The workaround that works fine: Call TF2Attributes and then make the transaction.

PHP Code:

    int AttributeIDs[15]; // Txn is never referenced here
    
int TotalAttribs TF2Attrib_ListDefIndices(WeaponEntityAttributeIDs);

    
Transaction Txn SQL_CreateTransaction(); 

But I still want an explanation on why or how the handle got wiped so that this mistake doesn't repeat itself again in the future.

Thanks!

Potato Uno 12-11-2016 14:17

Re: Transaction Handle wiped for no reason
 
This is the relevant code for the TF2Attrib native call

https://github.com/FlaminSarge/tf2at...ibutes.sp#L755

asherkin 12-11-2016 14:20

Re: Transaction Handle wiped for no reason
 
Your plugin:
PHP Code:

int AttributeIDs[15]; 

The native you are calling:
PHP Code:

SetNativeArray(2iAttribIndices16); 

This is why all natives dealing with strings and arrays are meant to take a size param...

Potato Uno 12-11-2016 14:29

Re: Transaction Handle wiped for no reason
 
Makes sense, thanks for the explanation!

Miu 12-11-2016 19:54

Re: Transaction Handle wiped for no reason
 
deja vu

FlaminSarge 12-11-2016 20:00

Re: Transaction Handle wiped for no reason
 
rip
Will fix on my end when I get a chance, but the plugin docs DO state that it's size 16, if worded a bit poorly.

@ash would you suggest the return value be at most the max length passed in, or the real number of attributes on the item, so that if the return is larger than the max length passed in, users will know that they have passed in too small a value?


All times are GMT -4. The time now is 19:49.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.