@@ -231,28 +231,42 @@ namespace proc {
231231 launch_session->display_guid
232232 );
233233
234- BOOST_LOG (info) << " Virtual Display created at " << vdisplayName;
234+ if (!vdisplayName.empty ()) {
235+ BOOST_LOG (info) << " Virtual Display created at " << vdisplayName;
235236
236- // Don't change display settings when no params are given
237- if (launch_session->width && launch_session->height && launch_session->fps ) {
238- // Apply display settings
239- VDISPLAY::changeDisplaySettings (vdisplayName.c_str (), render_width, render_height, launch_session->fps );
240- }
241- // Set virtual_display to true when everything went fine
242- this ->virtual_display = true ;
243- this ->display_name = platf::to_utf8 (vdisplayName);
237+ // Don't change display settings when no params are given
238+ if (launch_session->width && launch_session->height && launch_session->fps ) {
239+ // Apply display settings
240+ VDISPLAY::changeDisplaySettings (vdisplayName.c_str (), render_width, render_height, launch_session->fps );
241+ }
242+ // Set virtual_display to true when everything went fine
243+ this ->virtual_display = true ;
244+ this ->display_name = platf::to_utf8 (vdisplayName);
244245
245- // When using virtual display, we don't care which display user configured to use.
246- // So we always set output_name to the newly created virtual display as a workaround for
247- // empty name when probing graphics cards.
246+ // When using virtual display, we don't care which display user configured to use.
247+ // So we always set output_name to the newly created virtual display as a workaround for
248+ // empty name when probing graphics cards.
248249
249- config::video.output_name = display_device::map_display_name (this ->display_name );
250+ config::video.output_name = display_device::map_display_name (this ->display_name );
251+ } else {
252+ BOOST_LOG (warning) << " Virtual Display creation failed!" ;
253+ }
250254 }
251255 }
252- #endif
253256
254257 display_device::configure_display (config::video, *launch_session);
255258
259+ // We should not preserve display state when using virtual display.
260+ // It is already handled by Windows properly.
261+ if (this ->virtual_display ) {
262+ display_device::reset_persistence ();
263+ }
264+
265+ #else
266+
267+ display_device::configure_display (config::video, *launch_session);
268+
269+ #endif
256270
257271 // Probe encoders again before streaming to ensure our chosen
258272 // encoder matches the active GPU (which could have changed
@@ -543,7 +557,7 @@ namespace proc {
543557
544558 // Load the configured output_name first
545559 // to prevent the value being write to empty when the initial terminate happens
546- if (proc.initial_display .empty ()) {
560+ if (!has_run && proc.initial_display .empty ()) {
547561 proc.initial_display = config::video.output_name ;
548562 } else {
549563 // Restore output name to its original value
0 commit comments