- fix some crashes in the Shape2D VBO code due to unsound pointer usage (#1318)

This commit is contained in:
Gutawer 2021-02-25 15:49:41 +00:00 committed by GitHub
parent d6987ff6b2
commit 73dc528112
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 14 deletions

View file

@ -565,7 +565,7 @@ void F2DDrawer::AddShape(FGameTexture* img, DShape2D* shape, DrawParms& parms)
if (!shape->uploadedOnce) { if (!shape->uploadedOnce) {
shape->bufIndex = -1; shape->bufIndex = -1;
shape->buffers.Clear(); shape->buffers.Clear();
shape->lastCommand = nullptr; shape->lastCommand = -1;
} }
delete shape->lastParms; delete shape->lastParms;
shape->lastParms = new DrawParms(parms); shape->lastParms = new DrawParms(parms);
@ -647,12 +647,9 @@ void F2DDrawer::AddShape(FGameTexture* img, DShape2D* shape, DrawParms& parms)
shape->uploadedOnce = true; shape->uploadedOnce = true;
} }
dg.shape2DBufIndex = shape->bufIndex; dg.shape2DBufIndex = shape->bufIndex;
dg.shapeLastCmd = true; shape->lastCommand += 1;
if (shape->lastCommand != nullptr) { dg.shape2DCommandCounter = shape->lastCommand;
shape->lastCommand->shapeLastCmd = false; AddCommand(&dg);
}
auto c = AddCommand(&dg);
shape->lastCommand = &mData[c];
offset = osave; offset = osave;
} }

View file

@ -125,7 +125,7 @@ public:
DShape2D* shape2D; DShape2D* shape2D;
int shape2DBufIndex; int shape2DBufIndex;
int shape2DIndexCount; int shape2DIndexCount;
bool shapeLastCmd; int shape2DCommandCounter;
RenderCommand() RenderCommand()
{ {
@ -262,7 +262,7 @@ public:
TArray<F2DVertexBuffer> buffers; TArray<F2DVertexBuffer> buffers;
bool needsVertexUpload = true; bool needsVertexUpload = true;
int bufIndex = -1; int bufIndex = -1;
F2DDrawer::RenderCommand* lastCommand = nullptr; int lastCommand = -1;
bool uploadedOnce = false; bool uploadedOnce = false;
DrawParms* lastParms; DrawParms* lastParms;

View file

@ -183,12 +183,15 @@ void Draw2D(F2DDrawer *drawer, FRenderState &state)
state.SetVertexBuffer(&cmd.shape2D->buffers[cmd.shape2DBufIndex]); state.SetVertexBuffer(&cmd.shape2D->buffers[cmd.shape2DBufIndex]);
state.DrawIndexed(DT_Triangles, 0, cmd.shape2DIndexCount); state.DrawIndexed(DT_Triangles, 0, cmd.shape2DIndexCount);
state.SetVertexBuffer(&vb); state.SetVertexBuffer(&vb);
if (cmd.shape2D->bufIndex > 0 && cmd.shapeLastCmd) if (cmd.shape2DCommandCounter == cmd.shape2D->lastCommand)
{ {
cmd.shape2D->needsVertexUpload = true; cmd.shape2D->lastCommand = -1;
cmd.shape2D->buffers.Clear(); if (cmd.shape2D->bufIndex > 0)
cmd.shape2D->lastCommand = nullptr; {
cmd.shape2D->bufIndex = -1; cmd.shape2D->needsVertexUpload = true;
cmd.shape2D->buffers.Clear();
cmd.shape2D->bufIndex = -1;
}
} }
cmd.shape2D->uploadedOnce = false; cmd.shape2D->uploadedOnce = false;
} }