I’m currently creating a stealth/detection system that uses a vector (the std C++ list, not points in 3D space) belonging the the NPC’s AI to keep track of how close an NPC is to detecting another pawn. ~ Every .25 seconds, a “detect” function is called to tick all relevant entries in the DetectionVector. I’ve been testing it with one NPC detecting only the player, and it runs flawlessly until approx. 1 min of run-time where I get the crash report:
MachineId:1629E91E4FEAC8CEF7551A90ACAA1D98
EpicAccountId:6339694411d143cbb8e2755eb87c3e48
Access violation - code c0000005 (first/second chance not available)
UE4Editor_CoreUObject + 1450875 bytes
UE4Editor_Engine + 6316830 bytes
UE4Editor_Engine + 6417331 bytes
UE4Editor_Engine + 5343028 bytes
UE4Editor_Engine + 3542178 bytes
UE4Editor_Engine + 9302478 bytes
UE4Editor_UnrealEd + 1806471 bytes
UE4Editor_UnrealEd + 6686342 bytes
UE4Editor!FEngineLoop::Tick() + 3876 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.6\engine\source\runtime\launch\private\launchengineloop.cpp:2214]
UE4Editor!GuardedMain() + 479 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.6\engine\source\runtime\launch\private\launch.cpp:131]
UE4Editor!GuardedMainWrapper() + 26 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.6\engine\source\runtime\launch\private\windows\launchwindows.cpp:126]
UE4Editor!WinMain() + 249 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.6\engine\source\runtime\launch\private\windows\launchwindows.cpp:202]
UE4Editor!__tmainCRTStartup() + 329 bytes [f:\dd\vctools\crt\crtw32\dllstuff\crtexe.c:618]
The relevant part of the function is here:
index = FindDetectionInfo(target); //Find our target DetectionInfo
if (index != -1) //If an info was found, store it
{
DetInfo = DetectionVector.at(index);
}
else //Otherwise, make a new one and store that
{
DetectionVector.push_back(new UDetectionInfo(target, 0.0));
DetInfo = DetectionVector.back();
}
And the FindDetectionInfo function:
int32 AnpcAI::FindDetectionInfo(APawn* target)
{
bool foundInfo = false;
int foundIndex = -1;
for (int i = 0; i < DetectionVector.size() && !foundInfo; i++) //Iterate through the vector until we find our Info
{
if (DetectionVector.at(i)->getTarget() == target)
{
foundInfo = true;
foundIndex = i;
}
}
return foundIndex;
}
I have already debugged this, ensuring that only one entry in the vector is created, that it updates properly, etc. I have also determined that these lines are what cause the crash. At this point, I believe that there may be a UE4 flaw rather than a scripting error, so any help/advise would be appreciated!
Other info:
Running on UE 4.6
Using Windows 7 x64
Vector is declared as: std::vector DetectionVector;