Repair Turret 2

by tiko13

A fork of Klonan's Repair Turret mod. It aims for repair turrets to be a complete replacement of construction bots (Logistic over time as well)

Content
8 days ago
2.0
1.26K
Logistics Logistic network

g Possible crash?

8 days ago
(updated 8 days ago)

I'll be level with you, I'm not sure WHAT exactly is causing this. Might be Hero Turrets Redux, might be this, might be this + Yuoki and their con bots, I don't know. The only thing I have is the current.log at the time of crash, and at the time of crash I was placing down more Repair Turrets to deal with an assault. This has been happening off and on for the past few days now, though initially I believed it to be a Hero Turrets Redux-related issue. (I'm on 1.1.8, I'll update to 1.1.9 now though I don't believe that will really change much for the crash)

1779.749 Error CrashHandler.cpp:503: Exception Code: c0000005, Address: 0x00007ff6a1ae0c21
ModuleBase: 0x00007ff6a0bb0000, ImageSize: 02a12000, RelativeAddress: 00f30c21
1779.749 Error CrashHandler.cpp:509: Access Violation: Read at address 000000000BADC216
1779.749 Error CrashHandler.cpp:523: Exception Context:
rax=0000000000000000, rbx=000002efce3af180, rcx=000000fb6425e578,
rdx=000002f3c504d200, rsi=000000fb6425e578, rdi=000002efce3af1a0,
rip=00007ff6a1ae0c21, rsp=000000fb6425e090, rbp=0000000000000000,
r8=000000000badc0de, r9=000002f3c3d32901, r10=0000000000000000,
r11=000000fb6425e070, r12=000002ef88e20160, r13=000002f34db084a8,
r14=000000fb6425e2f0, r15=000002f00601cee0
1779.749 Crashed in C:\Games\steamapps\common\Factorio\bin\x64\Factorio.exe (0x00007ff6a0bb0000 - 0x00007ff6a35c2000)
Factorio crashed. Generating symbolized stacktrace, please wait ...
C:\Users\build\AppData\Local\Temp\factorio-build-lGXlSm\libraries\StackWalker\StackWalker.cpp(924): StackWalker::ShowCallstack
C:\Users\build\AppData\Local\Temp\factorio-build-lGXlSm\src\Util\Logger.cpp(339): Logger::writeStacktrace
C:\Users\build\AppData\Local\Temp\factorio-build-lGXlSm\src\Util\Logger.cpp(381): Logger::logStacktrace
C:\Users\build\AppData\Local\Temp\factorio-build-lGXlSm\src\Util\CrashHandler.cpp(183): CrashHandler::writeStackTrace
C:\Users\build\AppData\Local\Temp\factorio-build-lGXlSm\src\Util\CrashHandler.cpp(552): CrashHandler::SehHandler
ERROR: SymGetLineFromAddr64, GetLastError: 487 (Address: 00007FFA4A3EC7E7)
00007FFA4A3EC7E7 (KERNELBASE): (filename not available): UnhandledExceptionFilter
ERROR: SymGetLineFromAddr64, GetLastError: 487 (Address: 00007FFA4C755998)
00007FFA4C755998 (ntdll): (filename not available): memset
ERROR: SymGetLineFromAddr64, GetLastError: 487 (Address: 00007FFA4C73CE76)
00007FFA4C73CE76 (ntdll): (filename not available): _C_specific_handler
ERROR: SymGetLineFromAddr64, GetLastError: 487 (Address: 00007FFA4C752A1F)
00007FFA4C752A1F (ntdll): (filename not available): _chkstk
ERROR: SymGetLineFromAddr64, GetLastError: 487 (Address: 00007FFA4C702554)
00007FFA4C702554 (ntdll): (filename not available): RtlRaiseException
ERROR: SymGetLineFromAddr64, GetLastError: 487 (Address: 00007FFA4C75152E)
00007FFA4C75152E (ntdll): (filename not available): KiUserExceptionDispatcher
C:\Users\build\AppData\Local\Temp\factorio-build-lGXlSm\src\Trigger\Shooter.cpp(735): Shooter::refreshBeams
C:\Users\build\AppData\Local\Temp\factorio-build-lGXlSm\src\Trigger\ShootingLogic.cpp(188): BeamShootingLogic::shootInternal
C:\Users\build\AppData\Local\Temp\factorio-build-lGXlSm\src\Trigger\ShootingLogic.cpp(267): ShootingLogic::shoot
C:\Users\build\AppData\Local\Temp\factorio-build-lGXlSm\src\Trigger\ShootingLogic.cpp(262): ShootingLogic::execute
C:\Users\build\AppData\Local\Temp\factorio-build-lGXlSm\src\Trigger\Shooter.cpp(561): Shooter::shootInternal
C:\Users\build\AppData\Local\Temp\factorio-build-lGXlSm\src\Entity\ElectricTurret.cpp(68): ElectricTurret::shootAt
C:\Users\build\AppData\Local\Temp\factorio-build-lGXlSm\src\Entity\Turret.cpp(814): Turret::finishUpdate
C:\Users\build\AppData\Local\Temp\factorio-build-lGXlSm\src\Entity\Turret.cpp(659): Turret::update
C:\Users\build\AppData\Local\Temp\factorio-build-lGXlSm\src\Surface\ActiveEntitiesOrder.hpp(146): EntityOrderHelpers::EntityOrderList<LogisticRobot,ConstructionRobot,Inserter,Roboport,Loader,AssemblingMachine,AgriculturalTower,OldAgriculturalTower,Furnace,MiningDrill,FluidWagon,ArtilleryWagon,InfinityCargoWagon,CargoWagon,Locomotive,Character,Boiler,Generator,BurnerGenerator,Reactor,Lab,LandMine,ArtilleryFlare,ArtilleryProjectile,ArtilleryTurret,Beam,Car,SpiderVehicle,TemporaryContainer,CharacterCorpse,CombatRobot,CaptureRobot,Corpse,ElectricEnergyInterface,EnemySpawner,Explosion,FlameThrowerExplosion,FluidStream,FluidTurret,FlyingTextEntity,FusionGenerator,FusionReactor,Gate,HeatInterface,HighlightBoxEntity,InfinityContainer,InfinityPipe,ItemRequestProxy,OffshorePump,ParticleSource,PowerSwitch,Projectile,Pump,Valve,Radar,ProgrammableSpeaker,RocketSilo,RocketSiloRocket,CargoPod,SmokeWithTrigger,SpeechBubble,Sticker,Turret,AsteroidCollector,Asteroid,Thruster,SpiderUnit,Unit>::update
C:\Users\build\AppData\Local\Temp\factorio-build-lGXlSm\src\Surface\Surface.cpp(2447): Surface::update
C:\Users\build\AppData\Local\Temp\factorio-build-lGXlSm\src\Map\Map.cpp(1320): Map::updateEntities
C:\Users\build\AppData\Local\Temp\factorio-build-lGXlSm\src\Game.cpp(191): Game::update
C:\Users\build\AppData\Local\Temp\factorio-build-lGXlSm\src\Scenario\Scenario.cpp(1134): Scenario::updateStep
C:\Users\build\AppData\Local\Temp\factorio-build-lGXlSm\src\MainLoop.cpp(1436): MainLoop::gameUpdateStep
C:\Users\build\AppData\Local\Temp\factorio-build-lGXlSm\src\MainLoop.cpp(1229): MainLoop::gameUpdateLoop
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\include\functional(823): std::_Func_impl_no_alloc<MainLoop::mainLoopStep'::2'::<lambda_1>,void>::_Do_call
C:\Users\build\AppData\Local\Temp\factorio-build-lGXlSm\src\Util\WorkerThread.cpp(71): WorkerThread::loop
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\include\thread(56): std::thread::_Invoke<std::tuple<void (__cdecl QueuedSoundInstanceSDL::QueuedSoundData::)(void),QueuedSoundInstanceSDL::QueuedSoundData >,0,1>
minkernel\crts\ucrt\src\appcrt\startup\thread.cpp(97): thread_start<unsigned int (__cdecl)(void ),1>
ERROR: SymGetLineFromAddr64, GetLastError: 487 (Address: 00007FFA4B8F7374)
00007FFA4B8F7374 (KERNEL32): (filename not available): BaseThreadInitThunk
ERROR: SymGetLineFromAddr64, GetLastError: 487 (Address: 00007FFA4C6FCC91)
00007FFA4C6FCC91 (ntdll): (filename not available): RtlUserThreadStart
Stack trace logging done
1785.458 Error CrashHandler.cpp:190: Map tick at moment of crash: 54686536
1785.657 Info CrashHandler.cpp:318: Executable CRC: 983102098

7 days ago
(updated 7 days ago)

Hey, while it's hard to debug just from the stack, I can confidently say it is almost 100% that this is not a fault of this mod, which would almost certainly crash with a lua error, not c++ one.

Some nerd points:
As I said above, the error is a c++ crash (game engine itself, not a mod logic/bug)
ElectricTurret::shootAt comes from vanilla turrets (Here we are using Roboport as a base for repair turrets)
The addresses (r8=000000000badc0de etc) look as a classic heap corruption, probably some leftover pointer for an object which was freed before
Shooter::refreshBeams - this is also from vanilla turets, repair turrets uses separate lua entities for the beams

EDIT:
So i decided to look further and found where it comes from - the Hero turrets mod

more details:
Hero turrets has a system that captures a turret's priority targets and restores them to the replacement turret after n upgrade/rank-up. The bug is that entity references are stored without validation and later restored even if those entities have been destroyed

This only happens with electric because Shooter::refreshBeams is used by those, normal turrets just simply fail without a crash

Fix is to validate the targets before reassignment, so they are not assigned if they became invalid during the process:

in turrets.lua (\prototypes\scripts\turrets.lua)
Change line 632:
pcall(new_ghost.set_priority_target, index, priority_target)

to :
if priority_target ~= nil and priority_target.valid then
pcall(new_ghost.set_priority_target, index, priority_target)
end

AND on line 226 change:
new_entity.set_priority_target(index,priority_target)

to:
if priority_target ~= nil and priority_target.valid then
new_entity.set_priority_target(index, priority_target)
end

I would make a PR for it but the mod does not have a source linked (neither does this lol I should fix it)

7 days ago

Hey... THAT'S MY CODE.

You right, I'll get that fixed. I'm not super familiar with all the ins and outs of modding for Factorio, I just wanted my sweet,sweet hero turrets mod back so I made it happen.

I should indeed set my github to Public, so everyone can see my pushes of "You big dumby, you should have done X,Y, or Z"

7 days ago

I am also pretty new to factorio modding myself (but being a software developer kinda helps :D)

I think this kind of error is pretty hard (maybe even impossible) to foresee unless you have very deep knowledge about the game's workings

6 days ago

Thanks for the help! I'm not tech savvy to know a lua crash from a c++ one, hah. Glad it got sorted out relatively easily ^^

New response