Skip to content

Commit

Permalink
Check that allocations in SplineCommon succeed. Attempt at #11660 but…
Browse files Browse the repository at this point in the history
… not optimistic.
  • Loading branch information
hrydgard committed Jan 6, 2019
1 parent aaa4494 commit 79d4b0f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions GPU/Common/SplineCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,16 @@ void DrawEngineCommon::SubmitCurve(const void *control_points, const void *indic
// Simplify away bones and morph before proceeding
// There are normally not a lot of control points so just splitting decoded should be reasonably safe, although not great.
SimpleVertex *simplified_control_points = (SimpleVertex *)managedBuf.Allocate(sizeof(SimpleVertex) * (index_upper_bound + 1));
if (!simplified_control_points) {
ERROR_LOG(G3D, "Failed to allocate space for simplified control points, skipping curve draw");
return;
}

u8 *temp_buffer = managedBuf.Allocate(sizeof(SimpleVertex) * num_points);
if (!temp_buffer) {
ERROR_LOG(G3D, "Failed to allocate space for temp buffer, skipping curve draw");
return;
}

u32 origVertType = vertType;
vertType = NormalizeVertices((u8 *)simplified_control_points, temp_buffer, (u8 *)control_points, index_lower_bound, index_upper_bound, vertType);
Expand All @@ -531,6 +540,10 @@ void DrawEngineCommon::SubmitCurve(const void *control_points, const void *indic

// Make an array of pointers to the control points, to get rid of indices.
const SimpleVertex **points = (const SimpleVertex **)managedBuf.Allocate(sizeof(SimpleVertex *) * num_points);
if (!points) {
ERROR_LOG(G3D, "Failed to allocate space for control point pointers, skipping curve draw");
return;
}
for (int idx = 0; idx < num_points; idx++)
points[idx] = simplified_control_points + (indices ? ConvertIndex(idx) : idx);

Expand Down

0 comments on commit 79d4b0f

Please sign in to comment.