RhinoApp().ActiveDoc()->DrawToDC crash

Hi all,
differently from Rhinoceros 5 where the code works perfectly, in Rhinoceros 6 the last row (highlighted in boldface) makes the plugin crash. The dib has been correctly created.
Any idea how to fix the problem?

Thanks,
Giovanna

CRhinoView* view = RhinoApp().ActiveView();
if(view)
{
CRhinoObjectIterator it( CRhinoObjectIterator::normal_or_locked_objects, CRhinoObjectIterator::active_and_reference_objects );

			
ON::display_mode dm = view->ActiveViewport().DisplayMode();
view->ActiveViewport().SetDisplayMode(ON::wireframe_display);

ON_Color savedColor;
CRhinoAppAppearanceSettings appearanceSettings = RhinoApp().AppSettings().AppearanceSettings();
savedColor = appearanceSettings.m_viewport_background_color;
				
appearanceSettings.m_viewport_background_color = RGB(255,255,255);
RhinoApp().AppSettings().SetAppearanceSettings(appearanceSettings);		
view->ActiveViewport().SetShowConstructionAxes(false);
view->ActiveViewport().SetShowConstructionGrid(false);	

if(RhinoApp().ActiveDoc())							
**RhinoApp().ActiveDoc()->DrawToDC(it, dib, dib.Width(), dib.Height(), view->ActiveViewport().View(), TRUE, FALSE, FALSE, FALSE);** // crash here
}

Hi @gm_user,

Here is the Rhino 6 of capturing a view to a dib and then writing it to a file.

– Dale