Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
WinRT: fixed a potential memory-related crash in SDL_Renderer on Wind…
…ows Phone
  • Loading branch information
DavidLudwig committed Aug 28, 2013
1 parent 88ea6f9 commit 44755f8
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/render/direct3d11/SDL_render_d3d11.cpp
Expand Up @@ -1474,16 +1474,16 @@ D3D11_RenderDrawPoints(SDL_Renderer * renderer,
b = (float)(renderer->b / 255.0f);
a = (float)(renderer->a / 255.0f);

vector<VertexPositionColor> vertices;
vertices.reserve(count);
for (int i = 0; i < count; ++i) {
VertexPositionColor v = {XMFLOAT3(points[i].x, points[i].y, 0.0f), XMFLOAT2(0.0f, 0.0f), XMFLOAT4(r, g, b, a)};
vertices.push_back(v);
VertexPositionColor * vertices = SDL_stack_alloc(VertexPositionColor, count);
for (int i = 0; i < min(count, 128); ++i) {
const VertexPositionColor v = {XMFLOAT3(points[i].x, points[i].y, 0.0f), XMFLOAT2(0.0f, 0.0f), XMFLOAT4(r, g, b, a)};
vertices[i] = v;
}

D3D11_RenderStartDrawOp(renderer);
D3D11_RenderSetBlendMode(renderer, renderer->blendMode);
if (D3D11_UpdateVertexBuffer(renderer, &vertices[0], vertices.size() * sizeof(VertexPositionColor)) != 0) {
if (D3D11_UpdateVertexBuffer(renderer, vertices, (unsigned int)count * sizeof(VertexPositionColor)) != 0) {
SDL_stack_free(vertices);
return -1;
}

Expand All @@ -1493,8 +1493,8 @@ D3D11_RenderDrawPoints(SDL_Renderer * renderer,
nullptr,
nullptr);

D3D11_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST, vertices.size());

D3D11_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST, count);
SDL_stack_free(vertices);
return 0;
}

Expand All @@ -1510,16 +1510,16 @@ D3D11_RenderDrawLines(SDL_Renderer * renderer,
b = (float)(renderer->b / 255.0f);
a = (float)(renderer->a / 255.0f);

vector<VertexPositionColor> vertices;
vertices.reserve(count);
VertexPositionColor * vertices = SDL_stack_alloc(VertexPositionColor, count);
for (int i = 0; i < count; ++i) {
VertexPositionColor v = {XMFLOAT3(points[i].x, points[i].y, 0.0f), XMFLOAT2(0.0f, 0.0f), XMFLOAT4(r, g, b, a)};
vertices.push_back(v);
const VertexPositionColor v = {XMFLOAT3(points[i].x, points[i].y, 0.0f), XMFLOAT2(0.0f, 0.0f), XMFLOAT4(r, g, b, a)};
vertices[i] = v;
}

D3D11_RenderStartDrawOp(renderer);
D3D11_RenderSetBlendMode(renderer, renderer->blendMode);
if (D3D11_UpdateVertexBuffer(renderer, &vertices[0], vertices.size() * sizeof(VertexPositionColor)) != 0) {
if (D3D11_UpdateVertexBuffer(renderer,&vertices, (unsigned int)count * sizeof(VertexPositionColor)) != 0) {
SDL_stack_free(vertices);
return -1;
}

Expand All @@ -1529,8 +1529,8 @@ D3D11_RenderDrawLines(SDL_Renderer * renderer,
nullptr,
nullptr);

D3D11_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP, vertices.size());

D3D11_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP, count);
SDL_stack_free(vertices);
return 0;
}

Expand Down

0 comments on commit 44755f8

Please sign in to comment.