WinRT: fixed a potential memory-related crash in SDL_Renderer on Windows Phone
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
diff --git a/src/render/direct3d11/SDL_render_d3d11.cpp b/src/render/direct3d11/SDL_render_d3d11.cpp
index cee1edb..98b48ad 100644
--- a/src/render/direct3d11/SDL_render_d3d11.cpp
+++ b/src/render/direct3d11/SDL_render_d3d11.cpp
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}