From 21c2d3834270e43d9b9a1e2d6dee7fb6fae13f11 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Sun, 15 Apr 2018 16:05:29 +0200 Subject: [PATCH] - fix softpoly canvas drawing not restoring all globals properly - add null pointer check on camera --- src/polyrenderer/poly_renderer.cpp | 45 ++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/src/polyrenderer/poly_renderer.cpp b/src/polyrenderer/poly_renderer.cpp index d5e525bb0..4eb6c5b0e 100644 --- a/src/polyrenderer/poly_renderer.cpp +++ b/src/polyrenderer/poly_renderer.cpp @@ -62,11 +62,6 @@ void PolyRenderer::RenderView(player_t *player, DCanvas *target) RenderTarget = target; RenderToCanvas = false; - int width = SCREENWIDTH; - int height = SCREENHEIGHT; - float trueratio; - ActiveRatio(width, height, &trueratio); - //viewport->SetViewport(&Thread, width, height, trueratio); RenderActorView(player->mo, false); @@ -78,24 +73,40 @@ void PolyRenderer::RenderView(player_t *player, DCanvas *target) void PolyRenderer::RenderViewToCanvas(AActor *actor, DCanvas *canvas, int x, int y, int width, int height, bool dontmaplines) { - const bool savedviewactive = viewactive; + // Save a bunch of silly globals: + auto savedViewpoint = Viewpoint; + auto savedViewwindow = Viewwindow; + auto savedviewwindowx = viewwindowx; + auto savedviewwindowy = viewwindowy; + auto savedviewwidth = viewwidth; + auto savedviewheight = viewheight; + auto savedviewactive = viewactive; + auto savedRenderTarget = RenderTarget; - viewwidth = width; + // Setup the view: RenderTarget = canvas; RenderToCanvas = true; R_SetWindow(Viewpoint, Viewwindow, 12, width, height, height, true); - //viewport->SetViewport(&Thread, width, height, Viewwindow.WidescreenRatio); viewwindowx = x; viewwindowy = y; viewactive = true; + // Render: RenderActorView(actor, dontmaplines); Threads.MainThread()->FlushDrawQueue(); DrawerThreads::WaitForWorkers(); - RenderTarget = nullptr; RenderToCanvas = false; + + // Restore silly globals: + Viewpoint = savedViewpoint; + Viewwindow = savedViewwindow; + viewwindowx = savedviewwindowx; + viewwindowy = savedviewwindowy; + viewwidth = savedviewwidth; + viewheight = savedviewheight; viewactive = savedviewactive; + RenderTarget = savedRenderTarget; } void PolyRenderer::RenderActorView(AActor *actor, bool dontmaplines) @@ -126,10 +137,15 @@ void PolyRenderer::RenderActorView(AActor *actor, bool dontmaplines) PolyCameraLight::Instance()->SetCamera(Viewpoint, RenderTarget, actor); //Viewport->SetupFreelook(); - ActorRenderFlags savedflags = Viewpoint.camera->renderflags; - // Never draw the player unless in chasecam mode - if (!Viewpoint.showviewer) - Viewpoint.camera->renderflags |= RF_INVISIBLE; + ActorRenderFlags savedflags = 0; + if (Viewpoint.camera) + { + savedflags = Viewpoint.camera->renderflags; + + // Never draw the player unless in chasecam mode + if (!Viewpoint.showviewer) + Viewpoint.camera->renderflags |= RF_INVISIBLE; + } ScreenTriangle::FuzzStart = (ScreenTriangle::FuzzStart + 14) % FUZZTABLE; @@ -147,7 +163,8 @@ void PolyRenderer::RenderActorView(AActor *actor, bool dontmaplines) Scene.RenderTranslucent(&mainViewpoint); PlayerSprites.Render(Threads.MainThread()); - Viewpoint.camera->renderflags = savedflags; + if (Viewpoint.camera) + Viewpoint.camera->renderflags = savedflags; interpolator.RestoreInterpolations (); NetUpdate();