sskodje / ScreenRecorderLib

A .NET library for screen recording in Windows, using native Microsoft Media Foundation for realtime encoding to h264 video or PNG images.
MIT License
409 stars 93 forks source link

Azure pipelines run - AccessViolationException #273

Closed AdamMurray1 closed 2 months ago

AdamMurray1 commented 10 months ago

Here is the exception from the pipeline virtual machine. This error is happening the first time in the test run when I am calling into ScreenRecorderLib and creating my instance of Recorder, and then crashing the application.

image

with functionally the same error ( reported via pipelines)

2023-12-04T17:24:27.8112206Z ##[error]RunMessage : The active test run was aborted. Reason: Test host process crashed : Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. 2023-12-04T17:24:27.8114865Z ##[debug]Processed: ##vso[task.logissue type=error;]RunMessage : The active test run was aborted. Reason: Test host process crashed : Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. 2023-12-04T17:24:27.8116772Z Repeat 2 times: 2023-12-04T17:24:27.8117389Z -------------------------------- 2023-12-04T17:24:27.8117642Z at .GetMainOutput(IDXGIOutput**) 2023-12-04T17:24:27.8117975Z -------------------------------- 2023-12-04T17:24:27.8118375Z at ScreenRecorderLib.DisplayRecordingSource.get_MainMonitor() 2023-12-04T17:24:27.8118741Z at ScreenRecorderLib.SourceOptions.get_MainMonitor() 2023-12-04T17:24:27.8119111Z at ScreenRecorderLib.Recorder..ctor(ScreenRecorderLib.RecorderOptions) 2023-12-04T17:24:27.8119492Z at ScreenRecorderLib.Recorder.CreateRecorder()

Application This is being used in a test automation solution, the boiled down functionality is as follows. When running every test, create a recorder and start recording. After the test is done, stop the recorder and dispose of it, add it to test results. NUnit, Selenium, and WinAppDriver are the 3rd party tools being used.
image

Rough description of pipeline setup Build pipeline

Release pipeline

Am I doing something wrong here? I am unclear as to what would be going on here or if there is some missing dependency that is handled when this is run from visual studio.

Notes. On my development machine when debugging through visual studio this seems to work perfectly fine. The video(s) are generated and attached to the local TestExplorer results as I would expect. The same is true when running tests from visual studio on the virtual machine.

sskodje commented 10 months ago

Am I doing something wrong here? I am unclear as to what would be going on here or if there is some missing dependency that is handled when this is run from visual studio.

Notes. On my development machine when debugging through visual studio this seems to work perfectly fine. The video(s) are generated and attached to the local TestExplorer results as I would expect. The same is true when running tests from visual studio on the virtual machine.

It crashes with access violation as soon as it tries to enumerate the display adapters, which makes me suspect it's a permission issue. Is the process that runs the library run as a service? Windows Services cannot access the desktop ui, graphics card or any other graphics system, for security reasons. As far as i know, to be able to access the graphics systems, the application must be run in a desktop window, which may explain why it works when you run it through visual studio.