Skip to content

Commit

Permalink
Protect GetNextRef to avoid crashing if no scan context is initialize…
Browse files Browse the repository at this point in the history
…d (either no GerFirstRef or GenNextRef returned null once)

Should fix #232
  • Loading branch information
llde committed Aug 18, 2024
1 parent 33f3cc8 commit a61749c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
13 changes: 10 additions & 3 deletions obse/obse/Commands_MiscReference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -940,20 +940,27 @@ static const TESObjectCELL::ObjectListEntry* GetCellRefEntry(CellListVisitor vis

return entry;
}

/*
TODO document and rework cell scans when it make sense.
Add additional protections for bad callers.
*/
static TESObjectREFR* CellScan(Script* scriptObj, TESObjectCELL* cellToScan = NULL, UInt32 formType = 0, UInt32 cellDepth = 0, bool getFirst = false, bool includeTaken = false, bool includeDeleted = false ,ProjectileFinder* projFinder = NULL)
{
static std::map<UInt32, CellScanInfo> scanScripts;
UInt32 idx = scriptObj->refID;

if (getFirst)
scanScripts.erase(idx);

if (scanScripts.find(idx) == scanScripts.end())
bool isScriptUnRegistered = scanScripts.find(idx) == scanScripts.end();
if (isScriptUnRegistered && cellToScan)
{
scanScripts[idx] = CellScanInfo(cellDepth, formType, includeTaken, includeDeleted , cellToScan);
scanScripts[idx].FirstCell();
}
else if (isScriptUnRegistered && cellToScan == nullptr) {
Console_Print("[ERROR], attempted to call GetNextRef after a Null reference, without reinit the cell scan with GetFirstRef. In Script %08X", scriptObj->refID);
return nullptr;
}

CellScanInfo* info = &(scanScripts[idx]);

Expand Down
1 change: 1 addition & 0 deletions obse_whatsnew.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ xOBSE 22.10
- Avoid rare null pointer access in ShowRuntimeError (thanks @Fox2Code)
- Fix Menu{Tap/Hold/Release}Key commands not properly registering the button event for the UI.
- Fix xOBSE 22.7 regression for Useful House, now unmodified IR won't reset the stack extraDataList, possible if it was modified by another IR or directly by the engine.
- Fix CTD when GetNextRef is called in a script after returning a null reference, without a GetFirstRef call to reinitialize the scan.
Changes:
- Force C++20 Standard, modified some places for compliance
API:
Expand Down

0 comments on commit a61749c

Please sign in to comment.