irajsb / UE_CaptureSubsystem

Runtime video and screenshot capture system for Unreal Engine
MIT License
81 stars 14 forks source link

Crash when starting capture in UE5.2 #11

Closed ancho98 closed 4 months ago

ancho98 commented 4 months ago

I just use StartCapture in Level Blueprint

LoginId:db6364de4234a01f75ca4b92b3cb168f EpicAccountId:477dc34bc8ea42369e96133bb8eb6126

The error report display this.

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x00007ff994ea82fb

VCRUNTIME140
UnrealEditor_Core!UE::String::Private::ConcatFStrings<FString const &,FString>() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Private\Containers\String.cpp:676]
UnrealEditor_Core!FString::ConcatFF() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Private\Containers\String.cpp:752]
UnrealEditor_CaptureSubsystem!<lambda_e774434e92df38bee76464832d9aaa7c>::operator()() [C:\Workspace\DBAIMetaHumanNewVersion\Project_Ari\Plugins\CaptureSubsystem\Source\CaptureSubsystem\Private\CaptureSubsystemDirector.cpp:951]
UnrealEditor_CaptureSubsystem!UE::Core::Private::Function::TFunctionRefCaller<<lambda_e774434e92df38bee76464832d9aaa7c>,void __cdecl(void)>::Call() [C:\Program Files\Epic Games\UE_5.2\Engine\Source\Runtime\Core\Public\Templates\Function.h:475]
UnrealEditor_Core!TGraphTask<FAsyncGraphTask>::ExecuteTask() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\Async\TaskGraphInterfaces.h:1310]
UnrealEditor_Core!FNamedTaskThread::ProcessTasksNamedThread() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:758]
UnrealEditor_Core!FNamedTaskThread::ProcessTasksUntilQuit() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:649]
UnrealEditor_Core!FTaskGraphCompatibilityImplementation::WaitUntilTasksComplete() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:2123]
UnrealEditor_Engine!FTickTaskSequencer::ReleaseTickGroup() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\TickTaskManager.cpp:556]
UnrealEditor_Engine!FTickTaskManager::RunTickGroup() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\TickTaskManager.cpp:1583]
UnrealEditor_Engine!UWorld::RunTickGroup() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\LevelTick.cpp:770]
UnrealEditor_Engine!UWorld::Tick() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\LevelTick.cpp:1512]
UnrealEditor_UnrealEd!UEditorEngine::Tick() [D:\build\++UE5\Sync\Engine\Source\Editor\UnrealEd\Private\EditorEngine.cpp:1905]
UnrealEditor_UnrealEd!UUnrealEdEngine::Tick() [D:\build\++UE5\Sync\Engine\Source\Editor\UnrealEd\Private\UnrealEdEngine.cpp:519]
UnrealEditor!FEngineLoop::Tick() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\LaunchEngineLoop.cpp:5812]
UnrealEditor!GuardedMain() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Launch.cpp:188]
UnrealEditor!GuardedMainWrapper() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:107]
UnrealEditor!LaunchWindowsStartup() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:244]
UnrealEditor!WinMain() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:284]
UnrealEditor!__scrt_common_main_seh() [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288]
kernel32
ntdll

and in crash report print log like this

[2024.03.13-08.25.01:561][ 69]LogCaptureSubsystem: Capturing Video
[2024.03.13-08.25.01:561][ 69]LogCaptureSubsystem: Creating Director
[2024.03.13-08.25.01:561][ 69]LogCaptureSubsystem: Creating Audio Encoder 
[2024.03.13-08.25.01:562][ 69]LogBlueprintUserMessages: [LV_AIStudio_C_3] Capture start
[2024.03.13-08.25.01:594][ 73]LogTemp: Creating Encoder
[2024.03.13-08.25.01:594][ 73]LogCaptureSubsystem: Creating Encoder Thread
[2024.03.13-08.25.01:594][ 73]LogCaptureSubsystem: Creating Video encoder
[2024.03.13-08.25.01:594][ 73]LogCaptureSubsystem: nvenc added
[2024.03.13-08.25.01:594][ 73]LogCaptureSubsystem: Warning: Using software encoder
[2024.03.13-08.25.01:594][ 73]LogCaptureSubsystem: Creating Video Queue
[2024.03.13-08.25.01:595][ 73]LogCaptureSubsystem: Error: 삄♴荈᡻甀핥™㶀랞ã甀适诌䣖쮋胨ț䠀쎋ᇫ譌먃 Error: 

In LogErrorUE() function it print unicode. but I have no idea how can check the reason. because it called on TaskGraph

ancho98 commented 4 months ago

Another error add: When I play game and record to use 'selected viewport'. It makes crash. But if I played 'New Editor Window(PIE)' It work sometime.

And I thought plugin take a video and audio. But in my mp4 file there is no sound. tip for me.

irajsb commented 4 months ago

Plugin does record video and audio . Is your drivers up to date ? cause I can see [2024.03.13-08.25.01:594][ 73]LogCaptureSubsystem: Warning: Using software encoder which means it failed to create gpu encoder .

ancho98 commented 4 months ago

There is two type of error.

  1. When Capture video in editor(selected viewport). crash log
    
    [2024.03.14-02.20.59:558][179]LogCaptureSubsystem: Capturing Video
    [2024.03.14-02.20.59:559][179]LogCaptureSubsystem: Creating Director
    [2024.03.14-02.20.59:559][179]LogCaptureSubsystem: Creating Audio Encoder 
    [2024.03.14-02.20.59:560][179]LogBlueprintUserMessages: [LV_AIStudio_C_3] Capture start
    [2024.03.14-02.20.59:589][183]LogTemp: Creating Encoder
    [2024.03.14-02.20.59:589][183]LogCaptureSubsystem: Creating Encoder Thread
    [2024.03.14-02.20.59:589][183]LogCaptureSubsystem: Creating Video encoder
    [2024.03.14-02.20.59:589][183]LogCaptureSubsystem: nvenc added
    [2024.03.14-02.20.59:589][183]LogCaptureSubsystem: Warning: Using software encoder
    [2024.03.14-02.20.59:589][183]LogCaptureSubsystem: Creating Video Queue
    [2024.03.14-02.20.59:591][183]LogCaptureSubsystem: Allocating Video Filter 
crash report

LoginId:db6364de4234a01f75ca4b92b3cb168f EpicAccountId:477dc34bc8ea42369e96133bb8eb6126

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0xffffffffffffffff

ucrtbase ucrtbase ucrtbase UnrealEditor_Core!TStringBuilderBase::AppendV() [D:\build++UE5\Sync\Engine\Source\Runtime\Core\Private\Misc\StringBuilder.cpp:73] UnrealEditor_Core!UE::Logging::Private::BasicLogToTrace() [D:\build++UE5\Sync\Engine\Source\Runtime\Core\Private\Logging\StructuredLog.cpp:930] UnrealEditor_Core!UE::Logging::Private::BasicLog() [D:\build++UE5\Sync\Engine\Source\Runtime\Core\Private\Logging\StructuredLog.cpp:1002] UnrealEditor_CaptureSubsystem!::operator()() [C:\Workspace\DBAIMetaHumanNewVersion\Project_Ari\Plugins\CaptureSubsystem\Source\CaptureSubsystem\Private\CaptureSubsystemDirector.cpp:951] UnrealEditor_CaptureSubsystem!UE::Core::Private::Function::TFunctionRefCaller<,void __cdecl(void)>::Call() [C:\Program Files\Epic Games\UE_5.2\Engine\Source\Runtime\Core\Public\Templates\Function.h:475] UnrealEditor_Core!TGraphTask::ExecuteTask() [D:\build++UE5\Sync\Engine\Source\Runtime\Core\Public\Async\TaskGraphInterfaces.h:1310] UnrealEditor_Core!FNamedTaskThread::ProcessTasksNamedThread() [D:\build++UE5\Sync\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:758] UnrealEditor_Core!FNamedTaskThread::ProcessTasksUntilQuit() [D:\build++UE5\Sync\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:649] UnrealEditor_Core!FTaskGraphCompatibilityImplementation::WaitUntilTasksComplete() [D:\build++UE5\Sync\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:2123] UnrealEditor_Engine!FTickTaskSequencer::ReleaseTickGroup() [D:\build++UE5\Sync\Engine\Source\Runtime\Engine\Private\TickTaskManager.cpp:556] UnrealEditor_Engine!FTickTaskManager::RunTickGroup() [D:\build++UE5\Sync\Engine\Source\Runtime\Engine\Private\TickTaskManager.cpp:1583] UnrealEditor_Engine!UWorld::RunTickGroup() [D:\build++UE5\Sync\Engine\Source\Runtime\Engine\Private\LevelTick.cpp:770] UnrealEditor_Engine!UWorld::Tick() [D:\build++UE5\Sync\Engine\Source\Runtime\Engine\Private\LevelTick.cpp:1512] UnrealEditor_UnrealEd!UEditorEngine::Tick() [D:\build++UE5\Sync\Engine\Source\Editor\UnrealEd\Private\EditorEngine.cpp:1905] UnrealEditor_UnrealEd!UUnrealEdEngine::Tick() [D:\build++UE5\Sync\Engine\Source\Editor\UnrealEd\Private\UnrealEdEngine.cpp:519] UnrealEditor!FEngineLoop::Tick() [D:\build++UE5\Sync\Engine\Source\Runtime\Launch\Private\LaunchEngineLoop.cpp:5812] UnrealEditor!GuardedMain() [D:\build++UE5\Sync\Engine\Source\Runtime\Launch\Private\Launch.cpp:188] UnrealEditor!GuardedMainWrapper() [D:\build++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:107] UnrealEditor!LaunchWindowsStartup() [D:\build++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:244] UnrealEditor!WinMain() [D:\build++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:284] UnrealEditor!__scrt_common_main_seh() [D:\a_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288] kernel32 ntdll

3. When Capture video by using float viewport(PIE).
crash error log

[2024.03.14-02.17.36:564][293]LogCaptureSubsystem: Capturing Video [2024.03.14-02.17.36:622][293]LogViewport: Scene viewport resized to 1440x2560, mode WindowedFullscreen. [2024.03.14-02.17.36:632][293]LogCaptureSubsystem: Warning: Viewport resize detected Resizing render targets [2024.03.14-02.17.36:662][293]LogCaptureSubsystem: Creating Director [2024.03.14-02.17.36:662][293]LogCaptureSubsystem: Creating Audio Encoder [2024.03.14-02.17.36:663][293]LogBlueprintUserMessages: [LV_AIStudio_C_3] Capture start [2024.03.14-02.17.36:683][293]LogViewport: Scene viewport resized to 1434x2520, mode WindowedFullscreen. [2024.03.14-02.17.36:693][293]LogCaptureSubsystem: Warning: Viewport resize detected Resizing render targets [2024.03.14-02.17.36:711][295]LogTemp: Creating Encoder [2024.03.14-02.17.36:711][295]LogCaptureSubsystem: Creating Encoder Thread [2024.03.14-02.17.36:711][295]LogCaptureSubsystem: Creating Video encoder [2024.03.14-02.17.36:711][295]LogCaptureSubsystem: nvenc added [2024.03.14-02.17.36:711][295]LogCaptureSubsystem: Warning: Using software encoder [2024.03.14-02.17.36:712][295]LogCaptureSubsystem: Error: 殠쩽࣋ Error: 㳰쩽࣋ [2024.03.14-02.17.36:712][295]LogCaptureSubsystem: Ending Video [2024.03.14-02.17.36:712][295]LogCaptureSubsystem: Creating Video Queue [2024.03.14-02.17.36:713][295]LogCaptureSubsystem: Allocating Video Filter

crash report

LoginId:db6364de4234a01f75ca4b92b3cb168f EpicAccountId:477dc34bc8ea42369e96133bb8eb6126

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x00000000000004b0

UnrealEditor_D3D12RHI!FD3D12Texture::Lock() [D:\build++UE5\Sync\Engine\Source\Runtime\D3D12RHI\Private\D3D12Texture.cpp:1772] UnrealEditor_D3D12RHI!FD3D12DynamicRHI::LockTexture2D_RenderThread() [D:\build++UE5\Sync\Engine\Source\Runtime\D3D12RHI\Private\D3D12Texture.cpp:2144] UnrealEditor_CaptureSubsystem!UCaptureSubsystemDirector::GetScreenVideoData() [C:\Workspace\DBAIMetaHumanNewVersion\Project_Ari\Plugins\CaptureSubsystem\Source\CaptureSubsystem\Private\CaptureSubsystemDirector.cpp:322] UnrealEditor_CaptureSubsystem!UCaptureSubsystemDirector::OnBackBufferReady_RenderThread() [C:\Workspace\DBAIMetaHumanNewVersion\Project_Ari\Plugins\CaptureSubsystem\Source\CaptureSubsystem\Private\CaptureSubsystemDirector.cpp:224] UnrealEditor_CaptureSubsystem!TBaseUObjectMethodDelegateInstance<0,UCaptureSubsystemDirector,void __cdecl(SWindow &,TRefCountPtr const &),FDefaultDelegateUserPolicy>::ExecuteIfSafe() [C:\Program Files\Epic Games\UE_5.2\Engine\Source\Runtime\Core\Public\Delegates\DelegateInstancesImpl.h:552] UnrealEditor_SlateRHIRenderer!FSlateRHIRenderer::DrawWindow_RenderThread() [D:\build++UE5\Sync\Engine\Source\Runtime\SlateRHIRenderer\Private\SlateRHIRenderer.cpp:1434] UnrealEditor_SlateRHIRenderer!TEnqueueUniqueRenderCommandType<FSlateRHIRenderer::DrawWindows_Private'::51'::SlateDrawWindowsCommandName, >::DoTask() [D:\build++UE5\Sync\Engine\Source\Runtime\RenderCore\Public\RenderingThread.h:209] UnrealEditor_SlateRHIRenderer!TGraphTask<TEnqueueUniqueRenderCommandType<FSlateRHIRenderer::DrawWindows_Private'::51'::SlateDrawWindowsCommandName, > >::ExecuteTask() [D:\build++UE5\Sync\Engine\Source\Runtime\Core\Public\Async\TaskGraphInterfaces.h:1310] UnrealEditor_Core!FNamedTaskThread::ProcessTasksNamedThread() [D:\build++UE5\Sync\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:758] UnrealEditor_Core!FNamedTaskThread::ProcessTasksUntilQuit() [D:\build++UE5\Sync\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:649] UnrealEditor_RenderCore!RenderingThreadMain() [D:\build++UE5\Sync\Engine\Source\Runtime\RenderCore\Private\RenderingThread.cpp:416] UnrealEditor_RenderCore!FRenderingThread::Run() [D:\build++UE5\Sync\Engine\Source\Runtime\RenderCore\Private\RenderingThread.cpp:542] UnrealEditor_Core!FRunnableThreadWin::Run() [D:\build++UE5\Sync\Engine\Source\Runtime\Core\Private\Windows\WindowsRunnableThread.cpp:149]



two type of error look similar but call stack is bit different. 
ancho98 commented 4 months ago

When I call StartCapture() my viewport resized. Do you know why??

irajsb commented 4 months ago

Can you change to directx 11 and test again?

ancho98 commented 4 months ago

I tested capture with default ThirdPerson template and It worked very good. My main project have lots of plugins So I think one of them make crash with capture system. Or some of project setting error. But I can't pretend the reason yet

ancho98 commented 4 months ago
    // Open the video codec
    int Err = avcodec_open2(VideoEncoderCodecContext, EncoderCodec, nullptr);
    if (Err < 0)
    {
        // If the hardware codec fails to initialize, switch to the software codec
        if (strcmp(EncoderCodec->name, "h264_nvenc") == 0 || strcmp(EncoderCodec->name, "h264_amf") == 0)
        {
            EncoderCodec = avcodec_find_encoder(AV_CODEC_ID_H264);
            UE_LOG(LogCaptureSubsystem, Warning, TEXT("Using software encoder"));
            SetupEncoderContext(EncoderCodec, bit_rate);

            Err = avcodec_open2(VideoEncoderCodecContext, EncoderCodec, nullptr);

            if (Err < 0)
            {
                LogErrorUE("Video codec open error", Err, false);
            }
        }
        else
        {
            LogErrorUE("Video codec open error", Err, false);
        }
    }

In this code I check the variables with debuger

int Err = avcodec_open2(VideoEncoderCodecContext, EncoderCodec, nullptr); Over here VideoEncoderCodecContext is fine. image But after avcodec_open2() function change codec to null and return 22 error. image

Error log print like this. The main is Invalid argument. image

Every error's cause this part. Do you know why the codec open function not work? In other project it work very fine. I have no idea about ffmpeg and avcodev lib. Thanks for your respond

ancho98 commented 4 months ago

I fixed it! image This is my blueprint node. when I turn on Show UI then It makes crash! and other issue was I put down file path in Video filter section! Thanks a lot.

I saw 'Show UI' option need to upgrade driver version or use dx11. Do you have any plan to change for use dx12 and Show UI option?

irajsb commented 4 months ago

The limitation of dx12 and show UI is not a issue on my side its limited on unreal engine side. even if it works in packaged game UI will still not show. for video file name make sure to pass a folder where user has permission to use ( for example not drive C ). There is a function called get recommended video file name that puts video in user documents but you can also put it inside the packaged game folder.

ancho98 commented 4 months ago

Got it! I tried show UI option with dx11 and used developers directory. It works correctly. Maybe I don't need to use capture UI now. It will be fine. Thank you!

ancho98 commented 4 months ago

And this is another simple question! Is the Bit Rate unit bps or kbps in Options?

irajsb commented 4 months ago

bits per second (bps)