Skip to content

Improve exception safety with smart pointers #1862

@elfring

Description

@elfring

Would you like to wrap any pointers with the class template “std::unique_ptr”?

Update candidates:

  • DebugRenderer::Vertex *vertices = new DebugRenderer::Vertex [vertex_count];
    inStream.ReadBytes(vertices, vertex_count * sizeof(DebugRenderer::Vertex));
    uint32 index_count;
    inStream.Read(index_count);
    uint32 *indices = new uint32 [index_count];
    inStream.ReadBytes(indices, index_count * sizeof(uint32));
    mBatches.insert({ id, mRenderer.CreateTriangleBatch(vertices, vertex_count, indices, index_count) });
    delete [] indices;
    delete [] vertices;
  • uint8 *palette = new uint8 [pal_bytes];
    inStream.read((char *)palette, pal_bytes);
    loaded = loaded && !inStream.fail();
    // Convert pixel data to a surface
    surface = new SoftwareSurface(header.mWidth, header.mHeight, format);
    surface->Lock(ESurfaceLockMode::Write);
    uint8 *scan_line = new uint8 [scan_width];
    for (int y = header.mHeight - 1; y >= 0; --y)
    {
    // Load one scan line
    inStream.read((char *)scan_line, scan_width);
    loaded = loaded && !inStream.fail();
    // Copy one scan line
    uint8 *in_pixel = scan_line;
    uint8 *out_pixel = (uint8 *)surface->GetScanLine(y);
    for (int x = 0; x < header.mWidth; ++x, ++in_pixel, out_pixel += pixel_size)
    memcpy(out_pixel, palette + (*in_pixel - header.mColorMapFirstEntryIndex) * pixel_size, pixel_size);
    }
    surface->UnLock();
    // Release temporaries
    delete [] palette;
    delete [] scan_line;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions