Skip to content

Commit 042040a

Browse files
committed
It works again. Extend testing to catch possible errors with it
1 parent eb569a4 commit 042040a

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

_testing/gmod_testing.lua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,24 @@ local ret, err = pcall(function()
119119
iFace:RunFile("includes/init.lua")
120120
iFace:RunString(code)
121121
iFace:RunHook("ExampleHook", "ExampleArg", 1234, true, Vector(1, 2, 3), Angle(4, 5, 6))
122+
123+
local startTime = SysTime()
124+
for k=1, 100000 do
125+
LuaThreaded.SetValue(k, "Some Random String")
126+
end
127+
local endTime = SysTime()
128+
print("Added 100.000 keys in " .. endTime - startTime .. "s")
129+
130+
local startTime = SysTime()
131+
for k=1, 100000 do
132+
LuaThreaded.SetValue(k, nil)
133+
end
134+
local endTime = SysTime()
135+
print("Removed 100.000 keys in " .. endTime - startTime .. "s")
136+
137+
if LuaThreaded.GetValue(1000) != nil then
138+
error("LuaThreaded.SetValue failed! Investigate!")
139+
end
122140
end)
123141

124142
if err then

source/lua_LuaThread.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,20 @@ LUA_FUNCTION(LuaThread_SetValue)
107107
if (type == GarrysMod::Lua::Type::Nil)
108108
{
109109
shared_table_mutex.Lock();
110+
ILuaValue* pKey = nullptr;
111+
ILuaValue* pVal = nullptr;
110112
for (auto& [sKey, sVal] : shared_table)
111113
{
112114
if (EqualValue(key, sKey))
113115
{
114-
SafeDelete(sKey);
115-
SafeDelete(sVal);
116+
pKey = sKey;
117+
pVal = sVal;
116118
break;
117119
}
118120
}
121+
122+
SafeDelete(pKey);
123+
SafeDelete(pVal);
119124
shared_table_mutex.Unlock();
120125
SafeDelete(key);
121126

@@ -139,9 +144,6 @@ LUA_FUNCTION(LuaThread_SetValue)
139144
{
140145
delete key;
141146
key = original_key;
142-
Msg("Found the original key.\n");
143-
} else {
144-
Msg("Didn't find the original key.\n");
145147
}
146148

147149
ILuaValue* val = original_value ? original_value : new ILuaValue;

0 commit comments

Comments
 (0)