Download

Access violation - code c0000005

Hi,

I some issue with a poisson disc distribution. the code was take from the Xaymar RandomDistributionPlugin

I get this stack error :


     Access violation - code c0000005 (first/second chance not available)
     
     UE4Editor_spaceShip!UPoissonDiscSampler::Distribute3D() + 911 bytes [d:\project\spaceship\source\spaceship\poissondiscsampler.cpp:168]
     UE4Editor_spaceShip!UPoissonDiscSampler::execDistribute3D() + 627 bytes [d:\project\spaceship\source\spaceship\poissondiscsampler.h:14]
     UE4Editor_CoreUObject!UFunction::Invoke() + 180 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\class.cpp:3713]
     UE4Editor_CoreUObject!UObject::CallFunction() + 1112 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:395]
     UE4Editor_CoreUObject!UObject::ProcessContextOpcode() + 141 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:1451]
     UE4Editor_CoreUObject!UObject::ProcessInternal() + 1644 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:602]
     UE4Editor_CoreUObject!UFunction::Invoke() + 180 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\class.cpp:3713]
     UE4Editor_CoreUObject!UObject::ProcessEvent() + 3036 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:924]
     UE4Editor_Engine!AActor::ProcessEvent() + 259 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\engine\private\actor.cpp:529]
     UE4Editor_Engine!AActor::ExecuteConstruction() + 655 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\engine\private\actorconstruction.cpp:552]
     UE4Editor_Engine!AActor::RerunConstructionScripts() + 3610 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\engine\private\actorconstruction.cpp:436]
     UE4Editor_Engine!ULevel::IncrementalUpdateComponents() + 521 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\engine\private\level.cpp:745]
     UE4Editor_Engine!UWorld::UpdateWorldComponents() + 820 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\engine\private\world.cpp:1215]
     UE4Editor_UnrealEd!FUnrealEdMisc::CB_MapChange() + 173 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\editor\unrealed\private\unrealedmisc.cpp:930]
     UE4Editor_UnrealEd!TBaseRawMethodDelegateInstance<0,FUnrealEdMisc,void __cdecl(unsigned int)>::ExecuteIfSafe() + 14 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\core\public\delegates\delegateinstancesimpl_variadics.inl:582]
     UE4Editor_UnrealEd!TBaseMulticastDelegate<void,unsigned int>::Broadcast() + 165 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\core\public\delegates\delegatesignatureimpl_variadics.inl:1030]
     UE4Editor_UnrealEd!UEditorEngine::Map_Load() + 7326 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\editor\unrealed\private\editorserver.cpp:2340]
     UE4Editor_UnrealEd!UEditorEngine::HandleMapCommand() + 349 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\editor\unrealed\private\editorserver.cpp:5680]
     UE4Editor_UnrealEd!UEditorEngine::Exec() + 797 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\editor\unrealed\private\editorserver.cpp:5180]
     UE4Editor_UnrealEd!UUnrealEdEngine::Exec() + 273 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\editor\unrealed\private\unrealedsrv.cpp:742]
     UE4Editor_UnrealEd!FEditorFileUtils::LoadMap() + 789 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\editor\unrealed\private\filehelpers.cpp:1910]
     UE4Editor_UnrealEd!FEditorFileUtils::LoadDefaultMapAtStartup() + 216 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\editor\unrealed\private\filehelpers.cpp:3070]
     UE4Editor_UnrealEd!FUnrealEdMisc::OnInit() + 2263 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\editor\unrealed\private\unrealedmisc.cpp:299]
     UE4Editor_UnrealEd!EditorInit() + 3254 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\editor\unrealed\private\unrealed.cpp:86]
     UE4Editor!GuardedMain() + 926 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\launch\private\launch.cpp:133]
     UE4Editor!GuardedMainWrapper() + 26 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\launch\private\windows\launchwindows.cpp:126]
     UE4Editor!WinMain() + 249 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\launch\private\windows\launchwindows.cpp:202]
     UE4Editor!__tmainCRTStartup() + 329 bytes [f:\dd\vctools\crt\crtw32\dllstuff\crtexe.c:618]

at line 168 I have this :


v3DSamples[iCell] = v3DSample;


from this function :


     void UPoissonDiscSampler::Distribute3D(TArray<FVector>& Samples, int32 Seed /* = 0 */, FVector Size /* = FVector2D(1.0f , 1.0f) */, float MinimumDistance /* = 1.0f */, int32 MaxStepSamples /* = 30 */, bool WrapX /* = false */, bool WrapY /* = false */, bool WrapZ /* = false */) {
         uint64 iCells, iCellsX, iCellsY, iCellsZ, iCell, iCellX, iCellY, iCellZ;
         double dCellSize;
         FVector* v3DSample; FVector** v3DSamples;
         TDoubleLinkedList<FVector*>* v3DList;
         FRandomStream rsRandomStream = FRandomStream(Seed);
     
         // Calculate cell size, count and total.
         dCellSize = MinimumDistance / sqrt(2.0);
         iCellsX = ceil(Size.X / dCellSize);
         iCellsY = ceil(Size.Y / dCellSize);
         iCellsZ = ceil(Size.Z / dCellSize);
         iCells = iCellsX * iCellsY * iCellsZ;
     
         // Initialize temporary arrays and lists for the generated elements.
         v3DSamples = new FVector*[iCells];
         v3DList = new TDoubleLinkedList<FVector*>();
         for (uint64 n = 0; n < iCells; ++n)
             v3DSamples[n] = NULL;
     
         // Generate starting sample.
         v3DSample = new FVector(rsRandomStream.FRandRange(0, Size.X), rsRandomStream.FRandRange(0, Size.Y), rsRandomStream.FRandRange(0, Size.Z));
         iCellX = (int)(v3DSample->X / dCellSize);
         iCellY = (int)(v3DSample->Y / dCellSize);
         iCellZ = (int)(v3DSample->Z / dCellSize);
         iCell = iCellX + (iCellY * iCellsX) + (iCellZ * iCellsX * iCellY);
         v3DSamples[iCell] = v3DSample;
         v3DList->AddTail(v3DSample);
     
         // Generate samples until the processing list is empty (no more samples can be generated).
         while (v3DList->Num() > 0) {
             FVector* v3DSampleOrigin = v3DList->GetHead()->GetValue();
     
             // Check if the retrieved sample is NULL instead of a valid vector,
             if (v3DSampleOrigin == NULL) { // and break out instead.
                 break;
             }
     
             // Now try and generate samples around the sample origin.
             bool bIsSuccessful = false;
             for (uint32 i = 0; i < (uint32)MaxStepSamples; ++i) {
                 double dYawAngle, dPitchAngle, dRadius;
                 dYawAngle = rsRandomStream.FRandRange(0, PI * 2.0f) + (double)i;
                 dPitchAngle = rsRandomStream.FRandRange(0, PI) + (double)i;
                 dRadius = rsRandomStream.FRandRange(1.0f, 2.0f) * (double)MinimumDistance;
                 v3DSample = new FVector(v3DSampleOrigin->X + (dRadius * cos(dYawAngle) * sin(dPitchAngle)),
                     v3DSampleOrigin->Y + (dRadius * sin(dYawAngle) * sin(dPitchAngle)),
                     v3DSampleOrigin->Z + (dRadius * cos(dPitchAngle)));
     
                 // Destroy sample if outside of boundaries.
                 if ((v3DSample->X < 0 || v3DSample->X > Size.X) || (v3DSample->Y < 0 || v3DSample->Y > Size.Y) || (v3DSample->Z < 0 || v3DSample->Z > Size.Z)) {
                     delete v3DSample; continue;
                 }
                 else {
                     // Check if it too close to any other sample generated.
                     iCellX = (uint64)(v3DSample->X / dCellSize);
                     iCellY = (uint64)(v3DSample->Y / dCellSize);
                     iCellZ = (uint64)(v3DSample->Z / dCellSize);
                     iCell = iCellX + (iCellY * iCellsX) + (iCellZ * iCellsX * iCellsY);
                     if (iCell < 0 || iCell > iCells) {
                         delete v3DSample; continue;
                     }
                     else {
                         for (int x = -2; x <= 2; x++) { // Loop through nearest grid points that are inside the radius.
                             for (int y = -2; y <= 2; y++) {
                                 for (int z = -2; z <= 2; z++) {
                                     float fRealX = v3DSample->X, fRealY = v3DSample->Y, fRealZ = v3DSample->Z;
                                     int64 iTempCellX = iCellX + x;
                                     int64 iTempCellY = iCellY + y;
                                     int64 iTempCellZ = iCellZ + z;
     
                                     if (!WrapX) {
                                         if (iTempCellX < 0 || iTempCellX >= (int64)iCellsX)
                                             continue;
                                     }
                                     else {
                                         if (iTempCellX < 0) {
                                             iTempCellX = iTempCellX + iCellsX;
                                             v3DSample->X = fRealX + Size.X;
                                         }
                                         else if (iTempCellX >= (int64)iCellsX) {
                                             iTempCellX = iTempCellX - iCellsX;
                                             v3DSample->X = fRealX - Size.X;
                                         }
                                     }
                                     if (!WrapY) {
                                         if (iTempCellY < 0 || iTempCellY >= (int64)iCellsY)
                                             continue;
                                     }
                                     else {
                                         if (iTempCellY < 0) {
                                             iTempCellY = iTempCellY + iCellsY;
                                             v3DSample->Y = fRealY + Size.Y;
                                         }
                                         else if (iTempCellY >= (int64)iCellsY) {
                                             iTempCellY = iTempCellY - iCellsY;
                                             v3DSample->Y = fRealY - Size.Y;
                                         }
                                     }
                                     if (!WrapZ) {
                                         if (iTempCellZ < 0 || iTempCellZ >= (int64)iCellsZ)
                                             continue;
                                     }
                                     else {
                                         if (iTempCellZ < 0) {
                                             iTempCellZ = iTempCellZ + iCellsZ;
                                             v3DSample->Z = fRealZ + Size.Z;
                                         }
                                         else if (iTempCellZ >= (int64)iCellsZ) {
                                             iTempCellZ = iTempCellZ - iCellsZ;
                                             v3DSample->Z = fRealZ - Size.Z;
                                         }
                                     }
                                     int64 iTempCell = iTempCellX + (iTempCellY * iCellsX) + (iTempCellZ * iCellsX * iCellsY);
     
                                     if (v3DSamples[iTempCell] != NULL) {
                                         double dDist = FVector::Dist(*v3DSamples[iTempCell], *v3DSample);
                                         if (dDist < MinimumDistance) {
                                             delete v3DSample;
                                             goto PoissonDisc2DCheckBreakout;
                                         }
                                     }
     
                                     if (WrapX || WrapY || WrapZ) {
                                         v3DSample->X = fRealX;
                                         v3DSample->Y = fRealY;
                                         v3DSample->Z = fRealZ;
                                     }
                                 }
                             }
                         }
                     }
                 }
     
                 v3DSamples[iCell] = v3DSample;
                 v3DList->AddTail(v3DSample);
                 bIsSuccessful = true;
     
             PoissonDisc2DCheckBreakout:;
                 //continue;
             }
     
             // If we weren't successful in generating any new points, remove this point from the working list.
             if (!bIsSuccessful)
                 v3DList->RemoveNode(v3DSampleOrigin);
         }
     
         // Fill up the output array with generated samples.
         for (uint64 n = 0; n < iCells; ++n) {
             if (v3DSamples[n] != NULL)
                 Samples.Add(*v3DSamples[n]);
         }
     
         // Destroy temporary arrays and lists.
         delete v3DSamples; delete v3DList;
     }

Hm, that’s a null pointer exception. Can you make sure, that you are not accessing an NULL pointer and/or that “v3DSamples[iCell]” is not out of bounce?

in fact I will not using this to do what I want,
the crash was occuring beacause some variable was not set correctly.

I have made an actor that can generate Asteroid (random mesh, random scale, random initial rotation) and give him some random direction vector.
but I want to do another actor, that can generate for an Asteroid Field, but I have some trouble on how generate it correctly, actualy this Poisson Distributing just get me out of memory, or simply crash

have you any other idea to get that ?