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(WeaponEntity, AttributeIDs); // 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(WeaponEntity, AttributeIDs);
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!