Skip to content

Commit

Permalink
Fixed: Potential crashed in some rare cases due to missing table defi…
Browse files Browse the repository at this point in the history
…nition reference

Added: Factorization `ProcessDSV` using table sequential creation
  • Loading branch information
dvdvideo1234 committed May 14, 2019
1 parent 467e483 commit 90c0335
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
3 changes: 2 additions & 1 deletion data/todo.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
1. Test ray intersection
2. Test coordinate system drawing on physgun snap and regular snap/stack
3. Test if the POA structures are drawn correctly by `oScreen:DrawPOA(...)`
3. Test if the POA structures are drawn correctly by `oScreen:DrawPOA(...)`
4. Force DSV auto generation and test if the processor will load them
20 changes: 11 additions & 9 deletions lua/autorun/trackassembly_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ local gtInitLogs = {"*Init", false, 0}

------ CONFIGURE ASMLIB ------
asmlib.InitBase("track","assembly")
asmlib.SetOpVar("TOOL_VERSION","6.522")
asmlib.SetOpVar("TOOL_VERSION","6.523")
asmlib.SetIndexes("V" , "x", "y", "z")
asmlib.SetIndexes("A" ,"pitch","yaw","roll")
asmlib.SetIndexes("WV",1,2,3)
Expand Down Expand Up @@ -211,7 +211,7 @@ if(SERVER) then
activrad,spnflat,igntype,nextx,nexty,nextz,nextpic,nextyaw,nextrol)
if(stSpawn) then
if(not asmlib.SetPosBound(trEnt,stSpawn.SPos or GetOpVar("VEC_ZERO"),pPly,bnderrmod)) then
asmlib.LogInstance(""..pPly:Nick().." snapped <"..trRec.Slot.."> outside bounds",gtArgsLogs); return nil end
asmlib.LogInstance("User "..pPly:Nick().." snapped <"..trRec.Slot.."> outside bounds",gtArgsLogs); return nil end
trEnt:SetAngles(stSpawn.SAng)
if(not asmlib.ApplyPhysicalSettings(trEnt,ignphysgn,freeze,gravity,physmater)) then
asmlib.LogInstance("Failed to apply physical settings",gtArgsLogs); return nil end
Expand Down Expand Up @@ -732,6 +732,7 @@ asmlib.CreateTable("PIECES",{
},
Cache = {
Record = function(makTab, tCache, snPK, arLine, vSrc)
local defTab = makTab:GetDefinition()
local stData = tCache[snPK]; if(not stData) then
tCache[snPK] = {}; stData = tCache[snPK] end
if(not asmlib.IsHere(stData.Type)) then stData.Type = arLine[2] end
Expand All @@ -741,7 +742,7 @@ asmlib.CreateTable("PIECES",{
if(not asmlib.IsHere(stData.Slot)) then stData.Slot = snPK end
local nOffsID = makTab:Match(arLine[4],4); if(not asmlib.IsHere(nOffsID)) then
asmlib.LogInstance("Cannot match <"..tostring(arLine[4])..
"> to "..defTab[4][1].." for "..tostring(snPK),vSrc); return false end
"> to "..defTab[4][1].." for <"..tostring(snPK)..">",vSrc); return false end
local stPOA = asmlib.RegisterPOA(stData,nOffsID,arLine[5],arLine[6],arLine[7])
if(not asmlib.IsHere(stPOA)) then
asmlib.LogInstance("Cannot process offset #"..tostring(nOffsID).." for "..
Expand Down Expand Up @@ -807,14 +808,14 @@ asmlib.CreateTable("ADDITIONS",{
if(not asmlib.IsHere(stData.Size)) then stData.Size = 0 end
if(not asmlib.IsHere(stData.Slot)) then stData.Slot = snPK end
local nCnt, sFld, nAddID = 2, "", makTab:Match(arLine[4],4)
if(not asmlib.IsHere(nAddID)) then asmlib.LogInstance("Cannot match "..defTab.Nick.." <"..
tostring(arLine[4]).."> to "..defTab[4][1].." for "..tostring(snPK),vSrc); return false end
if(not asmlib.IsHere(nAddID)) then asmlib.LogInstance("Cannot match <"..
tostring(arLine[4]).."> to "..defTab[4][1].." for <"..tostring(snPK)..">",vSrc); return false end
stData[nAddID] = {} -- LineID has to be set properly
while(nCnt <= defTab.Size) do sFld = defTab[nCnt][1]
stData[nAddID][sFld] = makTab:Match(arLine[nCnt],nCnt)
if(not asmlib.IsHere(stData[nAddID][sFld])) then -- ADDITIONS is full of numbers
asmlib.LogInstance("Cannot match "..defTab.Nick.." <"..tostring(arLine[nCnt]).."> to "..
defTab[nCnt][1].." for "..tostring(snPK),vSrc); return false
asmlib.LogInstance("Cannot match <"..tostring(arLine[nCnt]).."> to "..
defTab[nCnt][1].." for <"..tostring(snPK)..">",vSrc); return false
end; nCnt = (nCnt + 1)
end; stData.Size = nAddID; return true
end,
Expand Down Expand Up @@ -856,14 +857,15 @@ asmlib.CreateTable("PHYSPROPERTIES",{
Record = function(makTab, tCache, snPK, arLine, vSrc)
local skName = asmlib.GetOpVar("HASH_PROPERTY_NAMES")
local skType = asmlib.GetOpVar("HASH_PROPERTY_TYPES")
local defTab = makTab:GetDefinition()
local tTypes = tCache[skType]; if(not tTypes) then
tCache[skType] = {}; tTypes = tCache[skType]; tTypes.Size = 0 end
local tNames = tCache[skName]; if(not tNames) then
tCache[skName] = {}; tNames = tCache[skName] end
local iNameID = makTab:Match(arLine[2],2)
if(not asmlib.IsHere(iNameID)) then -- LineID has to be set properly
asmlib.LogInstance("Cannot match "..defTab.Nick.." <"..tostring(arLine[2])..
"> to "..defTab[2][1].." for "..tostring(snPK),vSrc); return false end
asmlib.LogInstance("Cannot match <"..tostring(arLine[2])..
"> to "..defTab[2][1].." for <"..tostring(snPK)..">",vSrc); return false end
if(not asmlib.IsHere(tNames[snPK])) then -- If a new type is inserted
tTypes.Size = (tTypes.Size + 1)
tTypes[tTypes.Size] = snPK; tNames[snPK] = {}
Expand Down
25 changes: 10 additions & 15 deletions lua/trackassembly/trackasmlib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1573,7 +1573,7 @@ function GetTransformPOA(sModel,sKey)
local mOA = ePiece:GetAttachment(ePiece:LookupAttachment(sKey)); if(not mOA) then
LogInstance("Attachment missing <"..sKey..">@"..sModel); return nil end
local vtPos, atAng = mOA[sKey].Pos, mOA[sKey].Ang -- Extract transform data
LogInstance("Extract <"..sKey.."><"..tostring(vtPos).."><"..tostring(atAng)..">")
LogInstance("Extract {"..sKey.."}<"..tostring(vtPos).."><"..tostring(atAng)..">")
return vtPos, atAng -- The function must return transform position and angle
end

Expand Down Expand Up @@ -1885,7 +1885,8 @@ function CreateTable(sTable,defTab,bDelete,bReload)
for iCnt = 1, defTab.Size do local defCol = defTab[iCnt]
defCol[3] = GetTerm(tostring(defCol[3] or symDis), symDis)
defCol[4] = GetTerm(tostring(defCol[4] or symDis), symDis)
end; libCache[defTab.Name] = {}; libQTable[defTab.Nick] = self
end; tableInsert(libQTable, defTab.Nick)
libCache[defTab.Name] = {}; libQTable[defTab.Nick] = self
-- Read table definition
function self:GetDefinition(vK)
if(vK) then return tabDef[vK] end; return tabDef
Expand All @@ -1908,7 +1909,7 @@ function CreateTable(sTable,defTab,bDelete,bReload)
-- Removes the object from the list
function self:Remove(vRet)
local qtDef = self:GetDefinition()
libQTable[qtDef.Nick] = nil
libQTable[qtDef.Nick] = nil
collectgarbage(); return vRet
end
-- Generates a timer settings table and keeps the defaults
Expand Down Expand Up @@ -2970,18 +2971,12 @@ function ProcessDSV(sDelim)
LogInstance("("..prf..") Failed CATEGORY") end
end
end
if(fileExists(dir.."PIECES.txt", "DATA")) then
if(not ImportDSV("PIECES", true, prf)) then
LogInstance("("..prf..") Failed PIECES") end
end
if(fileExists(dir.."ADDITIONS.txt", "DATA")) then
if(not ImportDSV("ADDITIONS", true, prf)) then
LogInstance("("..prf..") Failed ADDITIONS") end
end
if(fileExists(dir.."PHYSPROPERTIES.txt", "DATA")) then
if(not ImportDSV("PHYSPROPERTIES", true, prf)) then
LogInstance("("..prf..") Failed PHYSPROPERTIES") end
end
for iD = 1, #libQTable do local sNick = libQTable[iD]
if(fileExists(dir..sNick..".txt", "DATA")) then
if(not ImportDSV(sNick, true, prf)) then
LogInstance("("..prf..") Failed "..sNick) end
else LogInstance("("..prf..") Missing "..sNick) end
end
end
end; LogInstance("Success"); return true
end
Expand Down

0 comments on commit 90c0335

Please sign in to comment.