Megafunk / MassSample

My understanding of Unreal Engine 5's experimental ECS plugin with a small sample project.
MIT License
681 stars 112 forks source link

Crash on Linux UE 5.2 when shooting projectiles #55

Open maciello opened 1 year ago

maciello commented 1 year ago

It happens when you shoot a lot of projectiles in short succession.

Crash Log:

[2023.05.26-14.00.07:589][525]LogCore: Error: appError called: Assertion failed: !ErrorDetected || GIsAutomationTesting [File:Runtime/Core/Public/Misc/MTAccessDetector.h] [Line: 90] 
Acquiring a write access while there are ongoing read or write access

[2023.05.26-14.00.07:600][525]LogCore: Error: Error reentered: Assertion failed: !ErrorDetected || GIsAutomationTesting [File:Runtime/Core/Public/Misc/MTAccessDetector.h] [Line: 101] 
Another thread asked to have a read or write access during this write access

[2023.05.26-14.00.07:600][525]LogCore: === Critical error: ===
Unhandled Exception: SIGSEGV: invalid attempt to write memory at address 0x0000000000000003

[2023.05.26-14.00.07:600][525]LogCore: Assertion failed: !ErrorDetected || GIsAutomationTesting [File:Runtime/Core/Public/Misc/MTAccessDetector.h] [Line: 90] 
Acquiring a write access while there are ongoing read or write access

0x00007f9330675577 libUnrealEditor-MassSignals.so!UMassSignalProcessorBase::OnSignalReceived(FName, TArrayView<FMassEntityHandle const, int>) [/mnt/horde/++UE5/Sync/Engine/Source/./../Plugins/Runtime/MassGameplay/Source/MassSignals/Private/MassSignalProcessorBase.cpp:142]
0x00007f93306895e0 libUnrealEditor-MassSignals.so!TBaseUObjectMethodDelegateInstance<false, UMassSignalProcessorBase, void (FName, TArrayView<FMassEntityHandle const, int>), FDefaultDelegateUserPolicy>::ExecuteIfSafe(FName, TArrayView<FMassEntityHandle const, int>) const [/mnt/horde/++UE5/Sync/Engine/Source/Runtime/Core/Public/Delegates/DelegateInstancesImpl.h:550]
0x00007f93306898bf libUnrealEditor-MassSignals.so!void TMulticastDelegateBase<FDefaultDelegateUserPolicy>::Broadcast<IBaseDelegateInstance<void (FName, TArrayView<FMassEntityHandle const, int>), FDefaultDelegateUserPolicy>, TDelegate<void (FName, TArrayView<FMassEntityHandle const, int>), FDefaultDelegateUserPolicy>, FName, TArrayView<FMassEntityHandle const, int> >(FName, TArrayView<FMassEntityHandle const, int>) const [/mnt/horde/++UE5/Sync/Engine/Source/Runtime/Core/Public/Delegates/MulticastDelegateBase.h:204]
0x00007f9330675bc4 libUnrealEditor-MassSignals.so!UMassSignalSubsystem::SignalEntities(FName, TArrayView<FMassEntityHandle const, int>) [/mnt/horde/++UE5/Sync/Engine/Source/./../Plugins/Runtime/MassGameplay/Source/MassSignals/Private/MassSignalSubsystem.cpp:46]
0x00007f933098b6be libUnrealEditor-MassCommunitySample.so!UMSProjectileOctreeQueryProcessors::Execute(FMassEntityManager&, FMassExecutionContext&) [/home/user/Documents/Unreal Projects/5.2/Engine/Source/../../MassSample/Plugins/MassCommunitySample/Source/MassCommunitySample/ProjectileSim/Processors/MSProjectileSimProcessors.cpp:268]
0x00007f935c0c8136 libUnrealEditor-MassEntity.so!UMassProcessor::CallExecute(FMassEntityManager&, FMassExecutionContext&) [/mnt/horde/++UE5/Sync/Engine/Source/./../Plugins/Runtime/MassEntity/Source/MassEntity/Private/MassProcessor.cpp:213]
0x00007f935c119322 libUnrealEditor-MassEntity.so!FMassProcessorTask::DoTask(ENamedThreads::Type, TRefCountPtr<FGraphEvent> const&) [/mnt/horde/++UE5/Sync/Engine/Source/./../Plugins/Runtime/MassEntity/Source/MassEntity/Private/MassProcessor.cpp:75]
0x00007f935c119aac libUnrealEditor-MassEntity.so!TGraphTask<FMassProcessorTask>::ExecuteTask(TArray<FBaseGraphTask*, TSizedDefaultAllocator<32> >&, ENamedThreads::Type, bool) [/mnt/horde/++UE5/Sync/Engine/Source/Runtime/Core/Public/Async/TaskGraphInterfaces.h:1310]
0x00007f94ce511c38 libUnrealEditor-Core.so!void LowLevelTasks::FTask::Init<FTaskGraphCompatibilityImplementation::QueueTask(FBaseGraphTask*, bool, ENamedThreads::Type, ENamedThreads::Type)::'lambda'()>(char16_t const*, LowLevelTasks::ETaskPriority, FTaskGraphCompatibilityImplementation::QueueTask(FBaseGraphTask*, bool, ENamedThreads::Type, ENamedThreads::Type)::'lambda'()&&, LowLevelTasks::ETaskFlags)::'lambda'(bool)::operator()(bool) const [/mnt/horde/++UE5/Sync/Engine/Source/Runtime/Core/Public/Async/Fundamental/Task.h:499]
0x00007f94ce511731 libUnrealEditor-Core.so!LowLevelTasks::TTaskDelegate<LowLevelTasks::FTask* (bool), 48u>::TTaskDelegateImpl<void LowLevelTasks::FTask::Init<FTaskGraphCompatibilityImplementation::QueueTask(FBaseGraphTask*, bool, ENamedThreads::Type, ENamedThreads::Type)::'lambda'()>(char16_t const*, LowLevelTasks::ETaskPriority, FTaskGraphCompatibilityImplementation::QueueTask(FBaseGraphTask*, bool, ENamedThreads::Type, ENamedThreads::Type)::'lambda'()&&, LowLevelTasks::ETaskFlags)::'lambda'(bool), false>::CallAndMove(LowLevelTasks::TTaskDelegate<LowLevelTasks::FTask* (bool), 48u>&, void*, unsigned int, bool) [/mnt/horde/++UE5/Sync/Engine/Source/Runtime/Core/Public/Async/Fundamental/TaskDelegate.h:171]
0x00007f94ce5098ba libUnrealEditor-Core.so!LowLevelTasks::FTask::ExecuteTask() [/mnt/horde/++UE5/Sync/Engine/Source/Runtime/Core/Public/Async/Fundamental/Task.h:627]
0x00007f94ce4f6270 libUnrealEditor-Core.so!LowLevelTasks::FScheduler::ExecuteTask(LowLevelTasks::FTask*&) [/mnt/horde/++UE5/Sync/Engine/Source/./Runtime/Core/Private/Async/Fundamental/Scheduler.cpp:150]
0x00007f94ce4f6c57 libUnrealEditor-Core.so!bool LowLevelTasks::FScheduler::TryExecuteTaskFrom<LowLevelTasks::TLocalQueueRegistry<1024u>::TLocalQueue, &(LowLevelTasks::TLocalQueueRegistry<1024u>::TLocalQueue::DequeueGlobal(bool, bool)), false>(LowLevelTasks::TLocalQueueRegistry<1024u>::TLocalQueue*, LowLevelTasks::TLocalQueueRegistry<1024u>::FOutOfWork&, bool, bool) [/mnt/horde/++UE5/Sync/Engine/Source/./Runtime/Core/Private/Async/Fundamental/Scheduler.cpp:349]
0x00007f94ce4775b1 libUnrealEditor-Core.so!LowLevelTasks::FScheduler::WorkerMain(LowLevelTasks::FSleepEvent*, LowLevelTasks::TLocalQueueRegistry<1024u>::TLocalQueue*, unsigned int, bool) [/mnt/horde/++UE5/Sync/Engine/Source/./Runtime/Core/Private/Async/Fundamental/Scheduler.cpp:378]
0x00007f94ce659735 libUnrealEditor-Core.so!FThreadImpl::Run() [/mnt/horde/++UE5/Sync/Engine/Source/./Runtime/Core/Private/HAL/Thread.cpp:67]
0x00007f94ce637196 libUnrealEditor-Core.so!FRunnableThreadPThread::Run() [/mnt/horde/++UE5/Sync/Engine/Source/./Runtime/Core/Private/HAL/PThreadRunnableThread.cpp:25]
0x00007f94ce5e7403 libUnrealEditor-Core.so!FRunnableThreadPThread::_ThreadProc(void*) [/mnt/horde/++UE5/Sync/Engine/Source/Runtime/Core/Private/HAL/PThreadRunnableThread.h:187]
0x00007f94c32aebb5 libc.so.6!UnknownFunction(0x85bb4)
0x00007f94c3330d90 libc.so.6!UnknownFunction(0x107d8f)

[2023.05.26-14.00.07:610][525]LogExit: Executing StaticShutdownAfterError

changing the line from:

Context.GetMutableSubsystem<UMassSignalSubsystem>()->SignalEntities(MassSample::Signals::OnGetHit, Entities);

to:

Context.GetMutableSubsystem<UMassSignalSubsystem>()->SignalEntitiesDeferred(Context, MassSample::Signals::OnGetHit, Entities);

kinda makes it not crash but I don't know if it affects anything else negatively.

Megafunk commented 1 year ago

This one is scary... It's probably not intended to be able to signal from other threads in a non deferred way like this is. SignalEntitiesDeferred seems correct here (It just defers the signal with PushCommand) and in the worst case this delays things by a frame. If things start acting weird inside of a single frame we can try something nicer...

jcoder58 commented 8 months ago

I have a similar issue on Windows 11 running in PIE when shooting lots of balls. It fails the ensure check LocalState.GetWriterThreadId() == CurrentThreadId at line 585 of MTAccessDetector.h