[boskid][1.1.109] Crash querying surface during combat ": !entity->isToBeDeleted() was not true"

ahicks
Inserter
Inserter
Posts: 24
Joined: Sat Jul 13, 2024 10:45 pm
Contact:

[boskid][1.1.109] Crash querying surface during combat ": !entity->isToBeDeleted() was not true"

Post by ahicks »

I've written up a nice system which uses effect triggers to help get information on game features. We use it to gather up a bunch of information about the map. By replacing the created_effect trigger to get reasonably low latency reasonably accurate placement info. I mention this because the attached C++ stack trace looks like it's happening inside a surface query inside a trigger, which is something our code definitely can do. Sadly the code here is way too complicated for me to get you a minimum repro without Lua-side stack traces.

Enter combat with this system and boom, explosion. I think what is going on is that the entity is possibly destroyed before the trigger fires, but the deciding factor seems to be situations in which entities are being rapidly created and destroyed.

This is mod dev, so it's a branch of Factorio Access which is on GitHub doing it. I thus can't easily get you a version of that unless you want to clone down a moving target. Hopefully the stuff I'm attaching is enough? I'm going to try to lift the processing of stuff out of the trigger and see if that helps.

I'm probably being an idiot but I can't see how to upload the save or the crash report to the forum as attachments. This is the contents of my factorio.log:

Code: Select all

   0.001 2024-09-28 20:46:26; Factorio 1.1.109 (build 62320, win64, full)
   0.001 Operating system: Windows 10 (build 19045) 
   0.001 Program arguments: "C:\projects\in_progress\factorio_access\factorio\bin\x64\factorio.exe" "-c" "C:\projects\in_progress\factorio_access\factorio\config\config.ini" 
   0.001 Config path: C:/projects/in_progress/factorio_access/factorio/config/config.ini
   0.001 Read data path: C:/projects/in_progress/factorio_access/factorio/data
   0.001 Write data path: C:/projects/in_progress/factorio_access/factorio [154735/976144MB]
   0.001 Binaries path: C:/projects/in_progress/factorio_access/factorio/bin
   0.008 System info: [CPU: Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz, 12 cores, RAM: 16461/65474 MB, page: 16878/75202 MB, virtual: 4256/134217727 MB, extended virtual: 0 MB]
   0.022 Memory info:
   0.022  [0]: 04CD F4-2666C19-16GIS 16384 MB 2400 MHz 1.2 v
   0.022  [1]: 04CD F4-2666C19-16GIS 16384 MB 2400 MHz 1.2 v
   0.022  [2]: 04CD F4-2666C19-16GIS 16384 MB 2400 MHz 1.2 v
   0.022  [3]: 04CD F4-2666C19-16GIS 16384 MB 2400 MHz 1.2 v
   0.023 Display options: [FullScreen: 0] [VSync: 1] [UIScale: automatic (100.0%)] [Native DPI: 1] [Screen: 255] [Special: lmw] [Lang: en]
   0.147 Video driver: windows
   0.147 Available displays: 1
   0.147  [0]: \\.\DISPLAY1 - NVIDIA GeForce RTX 2060 {0x05, [0,0], 1920x1080, 32bit, 60Hz}
   0.210 [Direct3D11] Display: 0, Output: 0, DisplayAdapter: 0, RenderingAdapter: 0; d3dcompiler_47.dll
   0.384 Initialised Direct3D[0]: NVIDIA GeForce RTX 2060; id: 10de-1f08; driver: nvldumdx.dll 31.0.15.3623
   0.384   D3D Feature Level: 11.1, DXGI 1.5+, SwapChain: 3,flip-discard,-,-,-,none
   0.384   [Local Video Memory] Budget: 5200MB, CurrentUsage: 7MB, Reservation: 0/2728MB
   0.384   [Non-Local Vid.Mem.] Budget: 31969MB, CurrentUsage: 0MB, Reservation: 0/16112MB
   0.384   Tiled resources: Tier 2
   0.384   Unified Memory Architecture: No
   0.384   BGR 565 Supported: Yes
   0.384   MaximumFrameLatency: 3, GPUThreadPriority: 0
   0.384 Graphics settings preset: very-high
   0.384   Dedicated video memory size 5968 MB
   0.423 Desktop composition is active.
   0.423 Graphics options: [Graphics quality: normal] [Video memory usage: all] [DXT: high-quality] [Color: 16bit]
   0.423                   [Max threads (load/render): 32/12] [Max texture size: 0] [Tex.Stream.: 0] [Rotation quality: normal] [Other: STDCWT] [B:0,C:0,S:100]
   0.446 [Audio] Backend:SDL(default); Driver:wasapi, Device:Default device, Depth:16, Channels:2, Frequency:44100
   0.559 Logitech LED Controller initialized.
   0.560 Error SteelSeriesGameSenseWindowsController.cpp:118: Failed to start SteelSeries GameSense. Error when processing coreProps.json file: GameSense address is empty
   0.596 Info ModManager.cpp:258: Found duplicate mod debugadapter, using higher version (1.1.45 > 1.1.43).
   0.604 Loading mod settings PavementDriveAssistContinued 4.1.1 (settings.lua)
   0.605 Loading mod settings VehicleSnap 1.18.5 (settings.lua)
   0.605 Loading mod settings Fill4Me 0.10.0 (settings.lua)
   0.606 Loading mod settings FactorioAccess 0.14.1 (settings-updates.lua)
   0.608 Loading mod core 0.0.0 (data.lua)
   0.653 Loading mod base 1.1.109 (data.lua)
   0.826 Loading mod PavementDriveAssistContinued 4.1.1 (data.lua)
   0.839 Loading mod VehicleSnap 1.18.5 (data.lua)
   0.852 Loading mod Fill4Me 0.10.0 (data.lua)
   0.861 Loading mod Kruise_Kontrol_Remote 0.1.11 (data.lua)
   0.869 Loading mod FactorioAccess 0.14.1 (data.lua)
   0.900 Loading mod base 1.1.109 (data-updates.lua)
   0.909 Loading mod FactorioAccess 0.14.1 (data-updates.lua)
   0.995 Checksum for core: 607699937
   0.995 Checksum of base: 1054619811
   0.995 Checksum of PavementDriveAssistContinued: 152228025
   0.995 Checksum of VehicleSnap: 3947302943
   0.995 Checksum of Fill4Me: 4197572416
   0.995 Checksum of Kruise_Kontrol_Remote: 847233213
   0.995 Checksum of stop-on-red: 0
   0.995 Checksum of FactorioAccess: 1935711860
   1.169 Prototype list checksum: 3201324457
   1.218 Loading sounds...
   1.441 Info PlayerData.cpp:76: Local player-data.json available, timestamp 1727581584
   1.441 Info PlayerData.cpp:83: Cloud player-data.json unavailable
   1.583 Initial atlas bitmap size is 16384
   1.589 Created atlas bitmap 16384x8700 [none]
   1.589 Created atlas bitmap 4096x2120 [decal]
   1.590 Created atlas bitmap 8192x2928 [low-object]
   1.591 Created atlas bitmap 4096x2576 [mipmap, linear-minification, linear-magnification, linear-mip-level]
   1.591 Created atlas bitmap 8192x3840 [terrain, mipmap, linear-minification, linear-mip-level]
   1.591 Created atlas bitmap 4096x1632 [terrain-effect-map, mipmap, linear-minification, linear-mip-level]
   1.592 Created atlas bitmap 4096x1664 [smoke, mipmap, linear-minification, linear-magnification]
   1.592 Created atlas bitmap 4096x944 [mipmap]
   1.593 Created atlas bitmap 8192x2288 [icon, not-compressed, mipmap, linear-minification, linear-magnification, linear-mip-level]
   1.593 Created atlas bitmap 4096x828 [alpha-mask]
   1.596 Created atlas bitmap 16384x4348 [shadow, linear-magnification, alpha-mask]
   1.596 Created atlas bitmap 4096x1328 [shadow, mipmap, linear-magnification, alpha-mask]
   1.597 Created atlas bitmap 2048x240 [icon-background, not-compressed, mipmap, linear-minification, linear-magnification, linear-mip-level, ]
   1.601 Texture processor created (2048). GPU accelerated compression Supported: yes, Enabled: yes/yes. Test passed. YCoCgDXT PSNR: 35.83, BC3 PSNR: 33.82
   2.223 Parallel Sprite Loader initialized (threads: 11)
   4.371 Sprites loaded
   4.384 Generated mipmaps (3) for atlas [2] of size 8192x2928   
   4.396 Generated mipmaps (3) for atlas [3] of size 4096x2576   
   4.407 Generated mipmaps (3) for atlas [4] of size 8192x3840   
   4.418 Generated mipmaps (3) for atlas [5] of size 4096x1632   
   4.429 Generated mipmaps (3) for atlas [6] of size 4096x1664   
   4.460 Generated mipmaps (3) for atlas [7] of size 4096x944   
   4.472 Generated mipmaps (5) for atlas [8] of size 8192x2288   
   4.484 Generated mipmaps (3) for atlas [11] of size 4096x1328   
   4.501 Custom mipmaps uploaded (1948)
   4.505 Error ControlSettings.cpp:864: decrease-inventory-bar-by-100 (custom-input): unknown alternative_key_sequence: CTRL + DOWN
   4.505 Error ControlSettings.cpp:864: decrease-train-wait-times-by-60 (custom-input): unknown alternative_key_sequence: CTRL + DOWN
   4.505 Error ControlSettings.cpp:864: increase-inventory-bar-by-100 (custom-input): unknown alternative_key_sequence: CTRL + UP
   4.505 Error ControlSettings.cpp:864: increase-train-wait-times-by-60 (custom-input): unknown alternative_key_sequence: CTRL + UP
   4.506 Warning ControlInputValue.cpp:497: Unknown control input string "h"
   4.510 Custom inputs active: 239
   4.596 Factorio initialised
   4.596 Discord overlay detected (DiscordHook64.dll)
   4.721 Loading map C:\projects\in_progress\factorio_access\factorio\saves\scantest.zip: 6880412 bytes.
   4.768 Loading level.dat: 11044140 bytes.
   4.771 Info Scenario.cpp:204: Map version 1.1.109-0
   4.958 Loading script.dat: 20697526 bytes.
   4.963 Checksum for script C:/projects/in_progress/factorio_access/factorio/temp/currently-playing/control.lua: 3702463597
   4.968 Checksum for script __PavementDriveAssistContinued__/control.lua: 2366682466
   4.969 Checksum for script __VehicleSnap__/control.lua: 4191411753
   4.974 Checksum for script __Fill4Me__/control.lua: 1272777333
   4.985 Checksum for script __Kruise_Kontrol_Remote__/control.lua: 3397731686
   4.987 Checksum for script __stop-on-red__/control.lua: 574778240
   5.032 Checksum for script __FactorioAccess__/control.lua: 1412686420
Factorio crashed. Generating symbolized stacktrace, please wait ...
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Script\LuaEntity.cpp (627): LuaEntity::LuaEntity
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Script\LuaSurface.cpp (1028): LuaSurface::luaFindEntitiesFiltered
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Script\LuaBinder.hpp (348): LuaBinder<LuaFlowStatistics<FlowStatistics<ID<FluidPrototype,unsigned short>,double,void> > >::callWrapperOnObject
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\libraries\Lua\ldo.c (352): luaD_precall
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\libraries\Lua\lvm.c (713): luaV_execute
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\libraries\Lua\lapi.c (1067): f_call
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\libraries\Lua\ldo.c (137): luaD_rawrunprotected
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\libraries\Lua\ldo.c (625): luaD_pcall
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\libraries\Lua\lapi.c (1093): lua_pcallk
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Util\LuaHelper.cpp (4460): LuaHelper::pCallWithStackTrace
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Script\LuaGameScript.cpp (1123): LuaGameScript::runEventHandler
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Script\LuaEventDispatcher.cpp (689): LuaEventDispatcher::run
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Script\LuaEventDispatcher.cpp (521): LuaEventDispatcher::dispatch
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Trigger\ScriptTriggerEffectItem.cpp (19): ScriptTriggerEffectItem::applyInternal
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Trigger\TriggerEffectItem.cpp (189): TriggerEffectItem::apply
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Trigger\TriggerEffect.cpp (32): TriggerEffect::apply
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Trigger\InstantTriggerDelivery.hpp (15): TriggerDelivery::apply
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Trigger\DirectTriggerItem.cpp (36): DirectTriggerItem::apply
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Trigger\Trigger.cpp (21): Trigger::apply
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Entity\Entity.cpp (445): Entity::postSetup
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Entity\ItemEntity.cpp (139): ItemEntity::postSetup
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Surface\Surface.cpp (202): Surface::setupEntity
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Surface\Surface.cpp (196): Surface::addEntity
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Surface\Surface.cpp (1196): Surface::createItemEntity
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Entity\TransportLine.cpp (670): TransportLine::dropItems
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Entity\TransportBelt.cpp (192): TransportBelt::dropItems
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Entity\TransportBeltConnectable.cpp (455): TransportBeltConnectable::preDieHook
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Entity\EntityWithHealth.cpp (569): EntityWithHealth::dieInternal
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Entity\EntityWithHealth.cpp (490): EntityWithHealth::die
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Entity\EntityWithHealth.cpp (418): EntityWithHealth::damage
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Entity\EntityWithOwner.cpp (207): EntityWithOwner::damage
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Trigger\DamageTriggerEffectItem.cpp (38): DamageTriggerEffectItem::applyInternal
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Trigger\TriggerEffectItem.cpp (189): TriggerEffectItem::apply
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Trigger\TriggerEffect.cpp (32): TriggerEffect::apply
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Trigger\DirectTriggerItem.cpp (36): DirectTriggerItem::apply
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Trigger\Trigger.cpp (21): Trigger::apply
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Trigger\Shooter.cpp (630): Shooter::doShoot
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Trigger\Shooter.cpp (503): Shooter::shootInternal
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Entity\Unit.cpp (207): Unit::attack
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\AI\PursueBehavior.cpp (112): PursueBehavior::execute
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\AI\GroupBehavior.cpp (134): GroupBehavior::execute
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\AI\Commandable.cpp (226): Commandable::runBehavior
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Entity\Unit.cpp (335): Unit::update
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Surface\ActiveEntitiesOrder.hpp (139): EntityOrderHelpers::EntityOrderList<LogisticRobot,ConstructionRobot,Inserter,Roboport,HeatPipe,Loader,AssemblingMachine,Furnace,MiningDrill,FluidWagon,ArtilleryWagon,CargoWagon,Locomotive,Character,Boiler,Generator,BurnerGenerator,Reactor,Lab,LandMine,ArithmeticCombinator,ArtilleryFlare,ArtilleryProjectile,ArtilleryTurret,Beam,Car,SpiderVehicle,CharacterCorpse,CombatRobot,Corpse,DeciderCombinator,ElectricEnergyInterface,EnemySpawner,Explosion,FireFlame,FlameThrowerExplosion,FluidStream,FluidTurret,FlyingText,Gate,HeatInterface,HighlightBoxEntity,InfinityContainer,InfinityPipe,ItemRequestProxy,OffshorePump,ParticleSource,PowerSwitch,Projectile,Pump,Radar,ProgrammableSpeaker,RocketSilo,RocketSiloRocket,SimpleSmoke,SmokeWithTrigger,SpeechBubble,Sticker,Turret,Unit>::update
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Surface\Surface.cpp (1643): Surface::update
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Map\Map.cpp (1634): Map::updateEntities
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Game.cpp (210): Game::update
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Scenario\Scenario.cpp (1318): Scenario::update
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Scenario\Scenario.cpp (1207): Scenario::updateStep
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\MainLoop.cpp (1372): MainLoop::gameUpdateStep
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\MainLoop.cpp (1225): 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<<lambda_c79c6392dc7bea77e6b27c3f2f6290ff>,void>::_Do_call
C:\Users\build\AppData\Local\Temp\factorio-build-BT1Yai\src\Util\WorkerThread.cpp (73): 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 SteelSeriesController::*)(void),SteelSeriesController *>,0,1>
minkernel\crts\ucrt\src\appcrt\startup\thread.cpp (97): thread_start<unsigned int (__cdecl*)(void *),1>
ERROR: SymGetLineFromAddr64, GetLastError: 487 (Address: 00007FFD0D567374)
00007FFD0D567374 (KERNEL32): (filename not available): BaseThreadInitThunk
ERROR: SymGetLineFromAddr64, GetLastError: 487 (Address: 00007FFD0EF1CC91)
00007FFD0EF1CC91 (ntdll): (filename not available): RtlUserThreadStart
Stack trace logging done
 106.977 Error LuaEntity.cpp:627: !entity->isToBeDeleted() was not true
 106.977 Error CrashHandler.cpp:641: Received 22
Logger::writeStacktrace skipped.
 106.977 Error CrashHandler.cpp:195: Map tick at moment of crash: 473905
 107.021 Info CrashHandler.cpp:315: Executable CRC: 1704422962
 107.021 Error Util.cpp:100: Unexpected error occurred. If you're running the latest version of the game you can help us solve the problem by posting the contents of the log file on the Factorio forums.
Please also include the save file(s), any mods you may be using, and any steps you know of to reproduce the crash.
 118.730 Uploading log file
 118.783 Error CrashHandler.cpp:266: Heap validation: success.
 118.783 Creating crash dump.
 118.995 CrashDump success
User avatar
PennyJim
Long Handed Inserter
Long Handed Inserter
Posts: 87
Joined: Wed Jan 18, 2023 3:49 am
Contact:

Re: [1.1.109] Crash querying surface during combat ": !entity->isToBeDeleted() was not true"

Post by PennyJim »

For attachments, it's a tab below the message box. It's on "Options" by default, but switching it over to "Attachments" will show you an "Add files" button.

Besides that, just dragging the file onto the message box should automatically add it as an attachment.
User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 3454
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [boskid][1.1.109] Crash querying surface during combat ": !entity->isToBeDeleted() was not true"

Post by boskid »

This looks like an extremally tricky corner case and one of the solutions will be to ban ItemEntity from having a created_effect that raises script events completly. This issue is happening mainly because of an extremally important piece of logic related to entities dying leaving a ghost as there is couple of things that must happen in an uninterrupted order (if entity is a transport belt it must drop items and then entity itself must be taken by an entity-ghost and registered on the surface) however by adding a script trigger to ItemEntity, script starts running when state of the world is temporarily inconsistent and so the crash happens. There are far more ways this can fail other than by searching entities on the surface so it looks like the only safe solution for this will be to disallow scripts events in those critical phases because running them is simply going to crash one way or the other.
User avatar
_CodeGreen
Long Handed Inserter
Long Handed Inserter
Posts: 74
Joined: Sat Mar 05, 2022 11:30 am
Contact:

Re: [boskid][1.1.109] Crash querying surface during combat ": !entity->isToBeDeleted() was not true"

Post by _CodeGreen »

Would it be possible to just defer the event until after the state is stable?
My Mods | If you can't make it perfect, make it adjustable
Post Reply

Return to “Assigned”