Editor crash when clicking on editor viewport

Hi,
I have the following problem:

I try to render custom debug information to the editor viewport, to be specific a Texture overlay.
To do it i registered a Delegate at the UDebugDrawService:

void FTestPluginClient::DrawOnDebugCanvas(UCanvas* Canvas, class APlayerController*) {
	if (InputTexture != NULL && InputTexture->Resource != NULL) {

		InputTexture->UpdateResource();
		InputTexture->WaitForStreaming();

		Canvas->DrawTile(InputTexture, Canvas->SizeX / 2, Canvas->SizeY / 2, Canvas->SizeX/2, Canvas->SizeY / 2, 0, 0, Width, Height, EBlendMode::BLEND_Opaque);
	}
}

DelegateHandle = UDebugDrawService::Register(TEXT("OnScreenDebug"), FDebugDrawDelegate::CreateRaw(this, &FTestPluginClient::DrawOnDebugCanvas));
			if (DelegateHandle.IsValid()) {
				UE_LOG(IndigoRenderLog, Log, TEXT("Have valid handle"));
			}
			else {
				UE_LOG(IndigoRenderLog, Log, TEXT("Have no valid handle"));
			}

This realy works fine until i try to left click inside the viewport. If i do the editor immediately crashes.

I tried to debug and VS tells me: “NewTextureRHI” was “0xFFFFFFFFFFFFFFFF”.
Here the Stacktrace:

>	[Inlineframe] UE4Editor-D3D11RHI.dll!GetD3D11TextureFromRHITexture(FRHITexture *) Line 586
 	UE4Editor-D3D11RHI.dll!FD3D11DynamicRHI::RHISetShaderTexture(FRHIPixelShader * PixelShaderRHI, unsigned int TextureIndex, FRHITexture * NewTextureRHI) Line 410
 	[Inlineframe] UE4Editor-Engine.dll!FRHICommandList::SetShaderTexture(FRHIPixelShader * TextureIndex, unsigned int) Line 1642
 	[Inlineframe] UE4Editor-Engine.dll!SetTextureParameter(FRHICommandList & Shader, FRHIPixelShader *) Line 209
 	UE4Editor-Engine.dll!FSimpleElementPS::SetParameters(FRHICommandList & RHICmdList, const FTexture * TextureValue) Line 90
 	UE4Editor-Engine.dll!FBatchedElements::PrepareShaders(FRHICommandList & RHICmdList, FGraphicsPipelineStateInitializer & GraphicsPSOInit, ERHIFeatureLevel::Type FeatureLevel, ESimpleElementBlendMode BlendMode, const FMatrix & Transform, bool bSwitchVerticalAxis, FBatchedElementParameters * BatchedElementParameters, const FTexture * Texture, bool bHitTesting, float Gamma, const FDepthFieldGlowInfo * GlowInfo, const FSceneView * View, TRefCountPtr<FRHITexture2D> DepthTexture) Line 746
 	UE4Editor-Engine.dll!FBatchedElements::Draw(FRHICommandList & RHICmdList, const FDrawingPolicyRenderState & DrawRenderState, ERHIFeatureLevel::Type FeatureLevel, bool bNeedToSwitchVerticalAxis, const FSceneView & View, bool bHitTesting, float Gamma, TRefCountPtr<FRHITexture2D> DepthTexture, EBlendModeFilter::Type Filter) Line 1166
 	UE4Editor-Engine.dll!FCanvasBatchedElementRenderItem::Render_RenderThread(FRHICommandListImmediate & RHICmdList, FDrawingPolicyRenderState & DrawRenderState, const FCanvas * Canvas) Line 398
 	UE4Editor-Engine.dll!FCanvas::Flush_RenderThread(FRHICommandListImmediate & RHICmdList, bool bForce) Line 710
 	UE4Editor-Engine.dll!FDebugCanvasDrawer::DrawRenderThread(FRHICommandListImmediate & RHICmdList, const void * InWindowBackBuffer) Line 196
 	UE4Editor-SlateRHIRenderer.dll!FSlateRHIRenderingPolicy::DrawElements(FRHICommandListImmediate & RHICmdList, FSlateBackBuffer & BackBuffer, TRefCountPtr<FRHITexture2D> & ColorTarget, TRefCountPtr<FRHITexture2D> & DepthStencilTarget, const TArray<FSlateRenderBatch,FDefaultAllocator> & RenderBatches, const TArray<FSlateClippingState,FDefaultAllocator> RenderClipStates, const FSlateRenderingOptions & Options) Line 1124
 	UE4Editor-SlateRHIRenderer.dll!FSlateRHIRenderer::DrawWindow_RenderThread(FRHICommandListImmediate & RHICmdList, FSlateRHIRenderer::FViewportInfo & ViewportInfo, FSlateWindowElementList & WindowElementList, bool bLockToVsync, bool bClear) Line 749
 	[Inlineframe] UE4Editor-SlateRHIRenderer.dll!FSlateRHIRenderer::DrawWindows_Private::__l29::<lambda_43e86ee7c51f39979e9a39d40b280024>::operator()(FRHICommandListImmediate &) Line 1034
 	[Inlineframe] UE4Editor-SlateRHIRenderer.dll!TEnqueueUniqueRenderCommandType<`FSlateRHIRenderer::DrawWindows_Private'::`29'::SlateDrawWindowsCommandName,<lambda_43e86ee7c51f39979e9a39d40b280024> >::DoTask(ENamedThreads::Type) Line 189
 	UE4Editor-SlateRHIRenderer.dll!TGraphTask<TEnqueueUniqueRenderCommandType<`FSlateRHIRenderer::DrawWindows_Private'::`29'::SlateDrawWindowsCommandName,<lambda_43e86ee7c51f39979e9a39d40b280024> > >::ExecuteTask(TArray<FBaseGraphTask *,FDefaultAllocator> & NewTasks, ENamedThreads::Type CurrentThread) Line 784
 	[Inlineframe] UE4Editor-Core.dll!FBaseGraphTask::Execute(TArray<FBaseGraphTask *,FDefaultAllocator> & CurrentThread, ENamedThreads::Type) Line 466
 	UE4Editor-Core.dll!FNamedTaskThread::ProcessTasksNamedThread(int QueueIndex, bool bAllowStall) Line 650
 	UE4Editor-Core.dll!FNamedTaskThread::ProcessTasksUntilQuit(int QueueIndex) Line 559
 	UE4Editor-RenderCore.dll!RenderingThreadMain(FEvent * TaskGraphBoundSyncEvent) Line 325
 	UE4Editor-RenderCore.dll!FRenderingThread::Run() Line 476
 	UE4Editor-Core.dll!FRunnableThreadWin::Run() Line 76
 	UE4Editor-Core.dll!FRunnableThreadWin::GuardedRun() Line 25
 	[Externer Code]

Has anyone a idea what is going on there? I assume that a texture is not accessible but why only if i click on the viewport?

I fixed the error. I changed the texture data of InputTexture while the scene was rererendered due to interactions (for example selecting an actor). The solution was to create a swap texture which will get updated before drawing it.