Editor Crash: DebugDrawPoint in FAsyncTask

Hi together,

during Recast creates the NavMesh-Tiles i call a method in a custom AActor to analyse data during NavMesh-creation. Tiles are created with FAsyncTask(s)/FRecastTileGeneratorTask.

Now i wanted to debug-draw information i get during this process. But as soon as i try to DebugDrawPoint the editor crashes. And i am not sure why… Below is the method causing the crash and a Screenshot to show where it crashes. Everything compiles fine though.

Thanks in advance,

void ARecastHeightfieldProcessor::ProcessHeightfield(rcCompactHeightfield& RasterContext)
{
    UE_LOG(LogTemp, Warning, TEXT("ProcessHeightfield called in subclass"));
    
    const rcCompactHeightfield* chf = &RasterContext;
    const int32 w = chf->width;
    const int32 h = chf->height;
    
    const float cs = chf->cs;
    const float ch = chf->ch;
    
    uint32 partId = 1;
    
    for (int32 y = 0; y < h; ++y) {
        for (int32 x = 0; x < w; ++x) {
            const float fx = chf->bmin[0] + x*cs;
            const float fz = chf->bmin[2] + y*cs;
            const rcCompactCell& c = chf->cells[x+y*w];
            for (int32 i = (int)c.index, ni = (int)(c.index+c.count); i < ni; ++i) {
                if (chf->areas[i] == RC_NULL_AREA) continue;
                
                const rcCompactSpan& s = chf->spans[i];
                const float fy = chf->bmin[1] + (s.y+1)*ch;
                
                partId +=1;
                
                
                const FVector v0 = FVector(fx, fy, fz);
                const FVector v1 = FVector(fx, fy, fz+cs);
                const FVector v2 = FVector(fx+cs, fy, fz+cs);
                const FVector v3 = FVector(fx+cs, fy, fz);
                
                
                // Causes the crash
                DrawDebugPoint(
                               GetWorld(),
                               v0,
                               10,                  //size
                               FColor(255,0,255),   //pink
                               false,               //persistent (never goes away)
                               0.03 				//point32 leaves a trail on moving object
                               );
            }
        }
    }
    
    UE_LOG(LogTemp, Warning, TEXT("n Parts %d") ,partId);
}

I could be wrong, but I think the DrawDebugX and associated linebatcher stuff can only be called from the game thread. Is your async task running on the game thread?

You are absolutely right. This will be the problem. I looked into the threading documentation and they explicitly urge not to DebugDrawX on any other thread than the game thread and NavMesh-generation definitely does not run on the game thread :slight_smile: If you`ll write an answer i will accept it.

Cheers! :slight_smile: