However, I'm getting a pretty weird crash, in release only; debug works fine. The app throws Access violation reading location 0x0000000000000F21 and this is the callstack I'm seeing:
I've stepped thru CreateNewTypeBatch() and the problem seems to be that what TypeBatches.AllocateUnsafely() returns is placed in bad location. Adding the ValidateUnsafeAdd() normally only performed only in debug does not help/trigger; putting a breakpoint there shows that Span does indeed have room for Count (in AllocateUnsafely)... yet when it returns, even trying to look at the value in the debugger will cause an access violation. OTOH the callstack seems to point to the jitter sooo... I'm a bit stumped.clrjit.dll!Compiler::fgAssignSetVarDef(GenTree * tree) Line 8983 C++
clrjit.dll!Compiler::fgMorphSmpOp(GenTree * tree, Compiler::MorphAddrContext * mac) Line 12387 C++
clrjit.dll!Compiler::fgMorphTree(GenTree * tree, Compiler::MorphAddrContext * mac) Line 15086 C++
clrjit.dll!Compiler::fgMorphStmts(BasicBlock * block, bool * lnot, bool * loadw) Line 15817 C++
clrjit.dll!Compiler::fgMorphBlocks() Line 16071 C++
clrjit.dll!Compiler::fgMorph() Line 17096 C++
clrjit.dll!Compiler::compCompile(void * * methodCodePtr, unsigned long * methodCodeSize, JitFlags * compileFlags) Line 4476 C++
clrjit.dll!Compiler::compCompileHelper(CORINFO_MODULE_STRUCT_ * classPtr, ICorJitInfo * compHnd, CORINFO_METHOD_INFO * methodInfo, void * * methodCodePtr, unsigned long * methodCodeSize, JitFlags * compileFlags, CorInfoInstantiationVerification) Line 6015 C++
clrjit.dll!Compiler::compCompile(CORINFO_METHOD_STRUCT_ * methodHnd, CORINFO_MODULE_STRUCT_ * classPtr, ICorJitInfo * compHnd, CORINFO_METHOD_INFO * methodInfo, void * * methodCodePtr, unsigned long * methodCodeSize, JitFlags * compileFlags) Line 5360 C++
clrjit.dll!jitNativeCode(CORINFO_METHOD_STRUCT_ * methodHnd, CORINFO_MODULE_STRUCT_ * classPtr, ICorJitInfo * compHnd, CORINFO_METHOD_INFO * methodInfo, void * * methodCodePtr, unsigned long * methodCodeSize, JitFlags * compileFlags, void * inlineInfoPtr) Line 6643 C++
clrjit.dll!CILJit::compileMethod(ICorJitInfo * compHnd, CORINFO_METHOD_INFO * methodInfo, unsigned int flags, unsigned char * * entryAddress, unsigned long * nativeSizeOfCode) Line 332 C++
[Managed to Native Transition]
> BepuPhysics.dll!BepuPhysics.ConstraintBatch.CreateNewTypeBatch(int typeId, BepuPhysics.Constraints.TypeProcessor typeProcessor, int initialCapacity, BepuUtilities.Memory.BufferPool pool) Line 107 C#
BepuPhysics.dll!BepuPhysics.ConstraintBatch.Allocate(int handle, ref int constraintBodyHandles, int bodyCount, BepuPhysics.Bodies bodies, int typeId, BepuPhysics.Constraints.TypeProcessor typeProcessor, int initialCapacity, BepuUtilities.Memory.BufferPool pool, out BepuPhysics.ConstraintReference reference) Line 139 C#
BepuPhysics.dll!BepuPhysics.Solver.AllocateInBatch(int targetBatchIndex, int constraintHandle, ref int bodyHandles, int bodyCount, int typeId, out BepuPhysics.ConstraintReference reference) Line 460 C#
BepuPhysics.dll!BepuPhysics.Solver.TryAllocateInBatch(int typeId, int targetBatchIndex, ref int bodyHandles, int bodyCount, out int constraintHandle, out BepuPhysics.ConstraintReference reference) Line 500 C#
BepuPhysics.dll!BepuPhysics.CollisionDetection.ContactConstraintAccessor<BepuPhysics.Constraints.Contact.Contact1, BepuPhysics.CollisionDetection.TwoBodyHandles, BepuPhysics.Constraints.Contact.Contact1AccumulatedImpulses, BepuPhysics.CollisionDetection.ContactImpulses1, BepuPhysics.CollisionDetection.ConstraintCache1>.FlushWithSpeculativeBatches<Lidgren.Physics.NarrowPhaseCallbacks>(ref BepuPhysics.CollisionDetection.UntypedList list, int narrowPhaseConstraintTypeId, ref BepuUtilities.Memory.Buffer<BepuUtilities.Memory.Buffer<ushort>> speculativeBatchIndices, BepuPhysics.Simulation simulation, BepuPhysics.CollisionDetection.PairCache pairCache) Line 163 C#
BepuPhysics.dll!BepuPhysics.CollisionDetection.NarrowPhase<Lidgren.Physics.NarrowPhaseCallbacks>.PendingConstraintAddCache.FlushWithSpeculativeBatches(BepuPhysics.Simulation simulation, ref BepuPhysics.CollisionDetection.PairCache pairCache) Line 170 C#
BepuPhysics.dll!BepuPhysics.CollisionDetection.NarrowPhase<Lidgren.Physics.NarrowPhaseCallbacks>.ExecutePreflushJob(int workerIndex, ref BepuPhysics.CollisionDetection.PreflushJob job) Line 183 C#
BepuPhysics.dll!BepuPhysics.CollisionDetection.NarrowPhase<Lidgren.Physics.NarrowPhaseCallbacks>.PreflushWorkerLoop(int workerIndex) Line 117 C#
Lidgren.Physics.Bepu2.dll!Lidgren.Physics.SimpleThreadDispatcher.DispatchThread(int workerIndex) Line 51 C#
It's a 100% repro on multiple computers. Any hints on what could be wrong, or actions I can take to work around this. Debug works decently well (which is a huge boon!) but Release needs to work eventually.
--michael