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
408 stars 93 forks source link

Null Pointer Exception on DisplayRecordingSource.get_MainMonitor: accessing GetMainOutput result without a null check #310

Closed ansarmie closed 1 month ago

ansarmie commented 1 month ago

We saw in some very rare cases the library fails to load the main Display with an NPE.

GetMainOutput is documented to return null sometimes, but get_MainMonitor tries to always access the object without a null check. We have observed instances where this leads to an NPE in our logs (when trying to initialize the displays from managed code).

Maybe we should instead allow the caller to handle the case where no Main Display was selected by checking if the returned Display is null (allowing the manage code to gracefully show a user facing error and recover).   https://github.com/sskodje/ScreenRecorderLib/blob/bcad5cf06fb4f7ed66dd8db5dc855a220fa7313b/ScreenRecorderLib/RecordingSources.h#L208

sskodje commented 1 month ago

Thanks for reporting, i'll check it out when i'm home from vacation :)

sskodje commented 1 month ago

Fixed with 8ae3b75