Fix GC shutdown crash due to canvas objects not getting GC'ed at the end

Fix typo in Draw2D and add support for specifying the viewport size directly
This commit is contained in:
Magnus Norddahl 2022-07-25 00:04:34 +02:00 committed by Christoph Oelckers
parent 6137ea12d1
commit b8569fa29f
4 changed files with 21 additions and 5 deletions

View file

@ -328,3 +328,4 @@ public:
};
void Draw2D(F2DDrawer* drawer, FRenderState& state);
void Draw2D(F2DDrawer* drawer, FRenderState& state, int x, int y, int width, int height);

View file

@ -51,13 +51,18 @@
CVAR(Bool, gl_aalines, false, CVAR_ARCHIVE)
void Draw2D(F2DDrawer *drawer, FRenderState &state)
void Draw2D(F2DDrawer* drawer, FRenderState& state)
{
const auto& mScreenViewport = screen->mScreenViewport;
Draw2D(drawer, state, mScreenViewport.left, mScreenViewport.top, mScreenViewport.width, mScreenViewport.height);
}
void Draw2D(F2DDrawer* drawer, FRenderState& state, int x, int y, int width, int height)
{
twoD.Clock();
const auto &mScreenViewport = screen->mScreenViewport;
state.SetViewport(mScreenViewport.left, mScreenViewport.top, mScreenViewport.width, mScreenViewport.height);
screen->mViewpoints->Set2D(state, twod->GetWidth(), twod->GetHeight());
state.SetViewport(x, y, width, height);
screen->mViewpoints->Set2D(state, drawer->GetWidth(), drawer->GetHeight());
state.EnableStencil(false);
state.SetStencil(0, SOP_Keep, SF_AllOn);

View file

@ -304,6 +304,7 @@ public:
};
class FCanvas;
extern TArray<FCanvas*> AllCanvases;
// A texture that can be drawn to.
@ -319,6 +320,15 @@ public:
aspectRatio = (float)width / height;
}
~FCanvasTexture()
{
if (Canvas)
{
AllCanvases.Delete(AllCanvases.Find(Canvas));
Canvas = nullptr;
}
}
void NeedUpdate() { bNeedsUpdate = true; }
void SetUpdated(bool rendertype) { bNeedsUpdate = false; bFirstUpdate = false; bLastUpdateType = rendertype; }
bool CheckNeedsUpdate() const { return bNeedsUpdate; }

View file

@ -359,7 +359,7 @@ sector_t* RenderView(player_t* player)
{
screen->RenderTextureView(canvas->Tex, [=](IntRect& bounds)
{
Draw2D(&canvas->Drawer, *screen->RenderState());
Draw2D(&canvas->Drawer, *screen->RenderState(), 0, 0, canvas->Tex->GetWidth(), canvas->Tex->GetHeight());
canvas->Drawer.Clear();
});
canvas->Tex->SetUpdated(true);