diff --git a/core/hw/naomi/printer.cpp b/core/hw/naomi/printer.cpp index 0b38efb45..6bb09da62 100644 --- a/core/hw/naomi/printer.cpp +++ b/core/hw/naomi/printer.cpp @@ -308,6 +308,8 @@ public: } bool save(const std::string& filename) { + if (page.empty()) + return false; for (u8& b : page) b = 0xff - b; stbi_write_png(filename.c_str(), printerWidth, lines, 1, &page[0], printerWidth); @@ -318,7 +320,7 @@ public: { ser << printerWidth; ser << (u32)page.size(); - ser.serialize(&page[0], page.size()); + ser.serialize(page.data(), page.size()); ser << lines; ser << penx; ser << peny; @@ -342,11 +344,11 @@ public: ser << cc.width; ser << cc.height; ser << (u32)cc.data.size(); - ser.serialize(&cc.data[0], cc.data.size()); + ser.serialize(cc.data.data(), cc.data.size()); } ser << (u32)ruledLine.size(); - ser.serialize(&ruledLine[0], ruledLine.size()); + ser.serialize(ruledLine.data(), ruledLine.size()); ser << ruledLineMode; ser << underline; ser << maxUnderline; @@ -357,7 +359,7 @@ public: u32 size; deser >> size; page.resize(size); - deser.deserialize(&page[0], page.size()); + deser.deserialize(page.data(), page.size()); deser >> lines; deser >> penx; deser >> peny; @@ -383,12 +385,12 @@ public: deser >> cc.height; deser >> size; cc.data.resize(size); - deser.deserialize(&cc.data[0], cc.data.size()); + deser.deserialize(cc.data.data(), cc.data.size()); } deser >> size; ruledLine.resize(size); - deser.deserialize(&ruledLine[0], ruledLine.size()); + deser.deserialize(ruledLine.data(), ruledLine.size()); deser >> ruledLineMode; deser >> underline; deser >> maxUnderline; @@ -655,7 +657,7 @@ public: ser << expectedDataBytes; ser << (u32)dataBytes.size(); - ser.serialize(&dataBytes[0], dataBytes.size()); + ser.serialize(dataBytes.data(), dataBytes.size()); ser << kanji; ser << kanjiByte0; @@ -666,7 +668,7 @@ public: ser << bm.width; ser << bm.height; ser << (u32)bm.data.size(); - ser.serialize(&bm.data[0], bm.data.size()); + ser.serialize(bm.data.data(), bm.data.size()); } if (bitmapWriter == nullptr) @@ -688,7 +690,7 @@ public: u32 size; deser >> size; dataBytes.resize(size); - deser.deserialize(&dataBytes[0], dataBytes.size()); + deser.deserialize(dataBytes.data(), dataBytes.size()); deser >> kanji; deser >> kanjiByte0; @@ -701,7 +703,7 @@ public: deser >> bm.height; deser >> size; bm.data.resize(size); - deser.deserialize(&bm.data[0], bm.data.size()); + deser.deserialize(bm.data.data(), bm.data.size()); } bool b; diff --git a/core/hw/pvr/ta_util.cpp b/core/hw/pvr/ta_util.cpp index 1bb61382f..3c878918a 100644 --- a/core/hw/pvr/ta_util.cpp +++ b/core/hw/pvr/ta_util.cpp @@ -367,8 +367,10 @@ void fix_texture_bleeding(const std::vector& polys, int first, int en // void makePrimRestartIndex(std::vector& polys, int first, int end, bool merge, rend_context& ctx) { + if (first >= (int)polys.size()) + return; PolyParam *last_poly = nullptr; - const PolyParam *end_poly = &polys[end]; + const PolyParam *end_poly = polys.data() + end; for (PolyParam *poly = &polys[first]; poly != end_poly; poly++) { int first_index; @@ -447,8 +449,10 @@ void makePrimRestartIndex(std::vector& polys, int first, int end, boo // void makeIndex(std::vector& polys, int first, int end, bool merge, rend_context& ctx) { + if (first >= (int)polys.size()) + return; PolyParam *last_poly = nullptr; - const PolyParam *end_poly = &polys[end]; + const PolyParam *end_poly = polys.data() + end; bool cullingReversed = false; for (PolyParam *poly = &polys[first]; poly != end_poly; poly++) { diff --git a/core/rend/boxart/http_client.cpp b/core/rend/boxart/http_client.cpp index 2efac6218..d68db142f 100644 --- a/core/rend/boxart/http_client.cpp +++ b/core/rend/boxart/http_client.cpp @@ -116,7 +116,7 @@ int post(const std::string& url, const std::vector& fields) return 500; } fclose(f); - content += std::string(&data[0], size); + content += std::string(data.data(), size); } content += "\r\n"; } diff --git a/core/rend/dx11/dx11_renderer.cpp b/core/rend/dx11/dx11_renderer.cpp index 495dfa815..d865b93c8 100644 --- a/core/rend/dx11/dx11_renderer.cpp +++ b/core/rend/dx11/dx11_renderer.cpp @@ -361,19 +361,19 @@ void DX11Renderer::uploadGeometryBuffers() { setFirstProvokingVertex(pvrrc); - size_t size = pvrrc.verts.size() * sizeof(decltype(pvrrc.verts[0])); + size_t size = pvrrc.verts.size() * sizeof(decltype(*pvrrc.verts.data())); bool rc = ensureBufferSize(vertexBuffer, D3D11_BIND_VERTEX_BUFFER, vertexBufferSize, size); verify(rc); D3D11_MAPPED_SUBRESOURCE mappedSubres; deviceContext->Map(vertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedSubres); - memcpy(mappedSubres.pData, &pvrrc.verts[0], size); + memcpy(mappedSubres.pData, pvrrc.verts.data(), size); deviceContext->Unmap(vertexBuffer, 0); - size = pvrrc.idx.size() * sizeof(decltype(pvrrc.idx[0])); + size = pvrrc.idx.size() * sizeof(decltype(*pvrrc.idx.data())); rc = ensureBufferSize(indexBuffer, D3D11_BIND_INDEX_BUFFER, indexBufferSize, size); verify(rc); deviceContext->Map(indexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedSubres); - memcpy(mappedSubres.pData, &pvrrc.idx[0], size); + memcpy(mappedSubres.pData, pvrrc.idx.data(), size); deviceContext->Unmap(indexBuffer, 0); if (config::ModifierVolumes && !pvrrc.modtrig.empty()) diff --git a/core/rend/dx11/oit/dx11_oitrenderer.cpp b/core/rend/dx11/oit/dx11_oitrenderer.cpp index 757eaa6fc..0267c1301 100644 --- a/core/rend/dx11/oit/dx11_oitrenderer.cpp +++ b/core/rend/dx11/oit/dx11_oitrenderer.cpp @@ -539,7 +539,7 @@ struct DX11OITRenderer : public DX11Renderer drawList(pvrrc.global_param_op, previous_pass.op_count, op_count); drawList(pvrrc.global_param_pt, previous_pass.pt_count, pt_count); - drawModVols(previous_pass.mvo_count, mvo_count, &pvrrc.global_param_mvo[0]); + drawModVols(previous_pass.mvo_count, mvo_count, pvrrc.global_param_mvo.data()); // // PASS 2: Render OP and PT to opaque render target @@ -575,9 +575,9 @@ struct DX11OITRenderer : public DX11Renderer { // Intel Iris Plus 640 just crashes if (current_pass.mv_op_tr_shared) - drawModVols(previous_pass.mvo_count, mvo_count, &pvrrc.global_param_mvo[0]); + drawModVols(previous_pass.mvo_count, mvo_count, pvrrc.global_param_mvo.data()); else - drawModVols(previous_pass.mvo_tr_count, current_pass.mvo_tr_count - previous_pass.mvo_tr_count, &pvrrc.global_param_mvo_tr[0]); + drawModVols(previous_pass.mvo_tr_count, current_pass.mvo_tr_count - previous_pass.mvo_tr_count, pvrrc.global_param_mvo_tr.data()); } } else diff --git a/core/rend/dx9/d3d_renderer.cpp b/core/rend/dx9/d3d_renderer.cpp index 36f455f42..e69dae12d 100644 --- a/core/rend/dx9/d3d_renderer.cpp +++ b/core/rend/dx9/d3d_renderer.cpp @@ -1009,20 +1009,20 @@ bool D3DRenderer::Render() v[1] = -1.f; device->SetClipPlane(3, v); - size_t size = pvrrc.verts.size() * sizeof(decltype(pvrrc.verts[0])); + size_t size = pvrrc.verts.size() * sizeof(decltype(*pvrrc.verts.data())); rc = ensureVertexBufferSize(vertexBuffer, vertexBufferSize, size); verify(rc); void *ptr; rc = SUCCEEDED(vertexBuffer->Lock(0, size, &ptr, D3DLOCK_DISCARD)); verify(rc); - memcpy(ptr, &pvrrc.verts[0], size); + memcpy(ptr, pvrrc.verts.data(), size); vertexBuffer->Unlock(); - size = pvrrc.idx.size() * sizeof(decltype(pvrrc.idx[0])); + size = pvrrc.idx.size() * sizeof(decltype(*pvrrc.idx.data())); rc = ensureIndexBufferSize(indexBuffer, indexBufferSize, size); verify(rc); rc = SUCCEEDED(indexBuffer->Lock(0, size, &ptr, D3DLOCK_DISCARD)); verify(rc); - memcpy(ptr, &pvrrc.idx[0], size); + memcpy(ptr, pvrrc.idx.data(), size); indexBuffer->Unlock(); if (config::ModifierVolumes && !pvrrc.modtrig.empty()) diff --git a/core/rend/gl4/gles.cpp b/core/rend/gl4/gles.cpp index 1772b22eb..413d175cf 100644 --- a/core/rend/gl4/gles.cpp +++ b/core/rend/gl4/gles.cpp @@ -875,12 +875,12 @@ bool OpenGL4Renderer::renderFrame(int width, int height) { //Main VBO //move vertex to gpu - gl4.vbo.getVertexBuffer()->update(&pvrrc.verts[0], pvrrc.verts.size() * sizeof(decltype(pvrrc.verts[0]))); - gl4.vbo.getIndexBuffer()->update(&pvrrc.idx[0], pvrrc.idx.size() * sizeof(decltype(pvrrc.idx[0]))); + gl4.vbo.getVertexBuffer()->update(pvrrc.verts.data(), pvrrc.verts.size() * sizeof(decltype(*pvrrc.verts.data()))); + gl4.vbo.getIndexBuffer()->update(pvrrc.idx.data(), pvrrc.idx.size() * sizeof(decltype(*pvrrc.idx.data()))); //Modvol VBO if (!pvrrc.modtrig.empty()) - gl4.vbo.getModVolBuffer()->update(&pvrrc.modtrig[0], pvrrc.modtrig.size() * sizeof(decltype(pvrrc.modtrig[0]))); + gl4.vbo.getModVolBuffer()->update(pvrrc.modtrig.data(), pvrrc.modtrig.size() * sizeof(decltype(*pvrrc.modtrig.data()))); // TR PolyParam data if (!pvrrc.global_param_tr.empty()) diff --git a/core/rend/gles/gles.cpp b/core/rend/gles/gles.cpp index 3b083c79e..9ff78586d 100644 --- a/core/rend/gles/gles.cpp +++ b/core/rend/gles/gles.cpp @@ -1142,10 +1142,10 @@ static void upload_vertex_indices() short_idx.reserve(pvrrc.idx.size()); for (u32 i : pvrrc.idx) short_idx.push_back(i); - gl.vbo.idxs->update(&short_idx[0], short_idx.size() * sizeof(u16)); + gl.vbo.idxs->update(short_idx.data(), short_idx.size() * sizeof(u16)); } else - gl.vbo.idxs->update(&pvrrc.idx[0], pvrrc.idx.size() * sizeof(decltype(pvrrc.idx[0]))); + gl.vbo.idxs->update(pvrrc.idx.data(), pvrrc.idx.size() * sizeof(decltype(*pvrrc.idx.data()))); glCheck(); } diff --git a/core/rend/vulkan/buffer.h b/core/rend/vulkan/buffer.h index 2f199f28e..4f443a75e 100644 --- a/core/rend/vulkan/buffer.h +++ b/core/rend/vulkan/buffer.h @@ -116,7 +116,8 @@ public: void upload(BufferData& bufferData, u32 bufOffset = 0) { - bufferData.upload(chunks.size(), &chunkSizes[0], &chunks[0], bufOffset); + if (!chunks.empty()) + bufferData.upload(chunks.size(), &chunkSizes[0], &chunks[0], bufOffset); } vk::DeviceSize size() const { diff --git a/core/rend/vulkan/drawer.cpp b/core/rend/vulkan/drawer.cpp index 964dbadf3..96e5d8538 100644 --- a/core/rend/vulkan/drawer.cpp +++ b/core/rend/vulkan/drawer.cpp @@ -262,7 +262,7 @@ void Drawer::DrawList(const vk::CommandBuffer& cmdBuffer, u32 listType, bool sor { if (first == last) return; - const PolyParam *pp_end = &polys[last]; + const PolyParam *pp_end = polys.data() + last; for (const PolyParam *pp = &polys[first]; pp != pp_end; pp++) if (pp->count > 2) DrawPoly(cmdBuffer, listType, sortTriangles, *pp, pp->first, pp->count); @@ -328,11 +328,11 @@ void Drawer::UploadMainBuffer(const VertexShaderUniforms& vertexUniforms, const BufferPacker packer; // Vertex - packer.add(&pvrrc.verts[0], pvrrc.verts.size() * sizeof(decltype(pvrrc.verts[0]))); + packer.add(pvrrc.verts.data(), pvrrc.verts.size() * sizeof(decltype(*pvrrc.verts.data()))); // Modifier Volumes - offsets.modVolOffset = packer.add(&pvrrc.modtrig[0], pvrrc.modtrig.size() * sizeof(decltype(pvrrc.modtrig[0]))); + offsets.modVolOffset = packer.add(pvrrc.modtrig.data(), pvrrc.modtrig.size() * sizeof(decltype(*pvrrc.modtrig.data()))); // Index - offsets.indexOffset = packer.add(&pvrrc.idx[0], pvrrc.idx.size() * sizeof(decltype(pvrrc.idx[0]))); + offsets.indexOffset = packer.add(pvrrc.idx.data(), pvrrc.idx.size() * sizeof(decltype(*pvrrc.idx.data()))); // Uniform buffers offsets.vertexUniformOffset = packer.addUniform(&vertexUniforms, sizeof(vertexUniforms)); offsets.fragmentUniformOffset = packer.addUniform(&fragmentUniforms, sizeof(fragmentUniforms)); diff --git a/core/rend/vulkan/drawer.h b/core/rend/vulkan/drawer.h index 17c385f16..863d74d9f 100644 --- a/core/rend/vulkan/drawer.h +++ b/core/rend/vulkan/drawer.h @@ -146,7 +146,7 @@ protected: vk::DeviceSize offset = -1; size_t n2LightSize = sizeof(N2LightModel) + align(sizeof(N2LightModel), GetContext()->GetUniformBufferAlignment()); - if (n2LightSize == sizeof(N2LightModel)) + if (n2LightSize == sizeof(N2LightModel) && !pvrrc.lightModels.empty()) { offset = packer.addUniform(&pvrrc.lightModels[0], pvrrc.lightModels.size() * sizeof(decltype(pvrrc.lightModels[0]))); } diff --git a/core/rend/vulkan/oit/oit_drawer.cpp b/core/rend/vulkan/oit/oit_drawer.cpp index 9151117f0..54ff60c0f 100644 --- a/core/rend/vulkan/oit/oit_drawer.cpp +++ b/core/rend/vulkan/oit/oit_drawer.cpp @@ -125,7 +125,7 @@ void OITDrawer::DrawList(const vk::CommandBuffer& cmdBuffer, u32 listType, bool { if (first == last) return; - const PolyParam *pp_end = &polys[last]; + const PolyParam *pp_end = polys.data() + last; for (const PolyParam *pp = &polys[first]; pp != pp_end; pp++) if (pp->count > 2) DrawPoly(cmdBuffer, listType, sortTriangles, pass, *pp, pp->first, pp->count); @@ -216,11 +216,11 @@ void OITDrawer::UploadMainBuffer(const OITDescriptorSets::VertexShaderUniforms& BufferPacker packer; // Vertex - packer.add(&pvrrc.verts[0], pvrrc.verts.size() * sizeof(decltype(pvrrc.verts[0]))); + packer.add(pvrrc.verts.data(), pvrrc.verts.size() * sizeof(decltype(*pvrrc.verts.data()))); // Modifier Volumes - offsets.modVolOffset = packer.add(&pvrrc.modtrig[0], pvrrc.modtrig.size() * sizeof(decltype(pvrrc.modtrig[0]))); + offsets.modVolOffset = packer.add(pvrrc.modtrig.data(), pvrrc.modtrig.size() * sizeof(decltype(*pvrrc.modtrig.data()))); // Index - offsets.indexOffset = packer.add(&pvrrc.idx[0], pvrrc.idx.size() * sizeof(decltype(pvrrc.idx[0]))); + offsets.indexOffset = packer.add(pvrrc.idx.data(), pvrrc.idx.size() * sizeof(decltype(*pvrrc.idx.data()))); // Uniform buffers offsets.vertexUniformOffset = packer.addUniform(&vertexUniforms, sizeof(vertexUniforms)); offsets.fragmentUniformOffset = packer.addUniform(&fragmentUniforms, sizeof(fragmentUniforms)); @@ -354,7 +354,7 @@ bool OITDrawer::Draw(const Texture *fogTexture, const Texture *paletteTexture) DrawList(cmdBuffer, ListType_Opaque, false, Pass::Depth, pvrrc.global_param_op, previous_pass.op_count, current_pass.op_count); DrawList(cmdBuffer, ListType_Punch_Through, false, Pass::Depth, pvrrc.global_param_pt, previous_pass.pt_count, current_pass.pt_count); - DrawModifierVolumes(cmdBuffer, previous_pass.mvo_count, current_pass.mvo_count - previous_pass.mvo_count, &pvrrc.global_param_mvo[0]); + DrawModifierVolumes(cmdBuffer, previous_pass.mvo_count, current_pass.mvo_count - previous_pass.mvo_count, pvrrc.global_param_mvo.data()); // Color subpass cmdBuffer.nextSubpass(vk::SubpassContents::eInline); @@ -403,9 +403,9 @@ bool OITDrawer::Draw(const Texture *fogTexture, const Texture *paletteTexture) if (GetContext()->GetVendorID() != VulkanContext::VENDOR_QUALCOMM) // Adreno bug { if (current_pass.mv_op_tr_shared) - DrawModifierVolumes(cmdBuffer, previous_pass.mvo_count, current_pass.mvo_count - previous_pass.mvo_count, &pvrrc.global_param_mvo[0]); + DrawModifierVolumes(cmdBuffer, previous_pass.mvo_count, current_pass.mvo_count - previous_pass.mvo_count, pvrrc.global_param_mvo.data()); else - DrawModifierVolumes(cmdBuffer, previous_pass.mvo_tr_count, current_pass.mvo_tr_count - previous_pass.mvo_tr_count, &pvrrc.global_param_mvo_tr[0]); + DrawModifierVolumes(cmdBuffer, previous_pass.mvo_tr_count, current_pass.mvo_tr_count - previous_pass.mvo_tr_count, pvrrc.global_param_mvo_tr.data()); } vk::Pipeline pipeline = pipelineManager->GetFinalPipeline(); diff --git a/core/stdclass.h b/core/stdclass.h index 2cd9b7efe..aa6583314 100644 --- a/core/stdclass.h +++ b/core/stdclass.h @@ -174,7 +174,7 @@ public: template MD5Sum& add(const std::vector& v) { - MD5_Update(&ctx, &v[0], (unsigned long)(v.size() * sizeof(T))); + MD5_Update(&ctx, v.data(), (unsigned long)(v.size() * sizeof(T))); return *this; }