summaryrefslogtreecommitdiff
path: root/tools/asset_packer.cc
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-03 08:03:57 +0100
committerskal <pascal.massimino@gmail.com>2026-02-03 08:03:57 +0100
commit6d4aeb4120230899589326b5fd87afca58654c05 (patch)
tree2b14534b9ab7bf0d1be203a0a8195dcc49a5bbfe /tools/asset_packer.cc
parentf7609d0bdc3df851195c378eabc2715cb4c30bbe (diff)
feat(assets): Enforce 16-byte alignment and string safety
Updates asset_packer to align static asset arrays to 16 bytes and append a null-terminator. This allows assets to be safely reinterpreted as typed pointers (e.g., float*, const char*) without copying. Updates AssetManager documentation to reflect these guarantees.
Diffstat (limited to 'tools/asset_packer.cc')
-rw-r--r--tools/asset_packer.cc11
1 files changed, 8 insertions, 3 deletions
diff --git a/tools/asset_packer.cc b/tools/asset_packer.cc
index 2b90ecc..d86e29b 100644
--- a/tools/asset_packer.cc
+++ b/tools/asset_packer.cc
@@ -210,7 +210,12 @@ int main(int argc, char* argv[]) {
}
std::vector<uint8_t> buffer((std::istreambuf_iterator<char>(asset_file)),
std::istreambuf_iterator<char>());
- fprintf(assets_data_cc_file, "static const uint8_t %s[] = {\n ",
+ size_t original_size = buffer.size();
+ buffer.push_back(0); // Null terminator for safety
+
+ fprintf(assets_data_cc_file, "const size_t ASSET_SIZE_%s = %zu;\n",
+ info.name.c_str(), original_size);
+ fprintf(assets_data_cc_file, "alignas(16) static const uint8_t %s[] = {\n ",
info.data_array_name.c_str());
for (size_t i = 0; i < buffer.size(); ++i) {
if (i > 0 && i % 12 == 0)
@@ -241,8 +246,8 @@ int main(int argc, char* argv[]) {
info.func_name_str_name.c_str(), info.params_array_name.c_str(),
info.proc_params.size());
} else {
- fprintf(assets_data_cc_file, "%s, sizeof(%s), false, nullptr, nullptr, 0",
- info.data_array_name.c_str(), info.data_array_name.c_str());
+ fprintf(assets_data_cc_file, "%s, ASSET_SIZE_%s, false, nullptr, nullptr, 0",
+ info.data_array_name.c_str(), info.name.c_str());
}
fprintf(assets_data_cc_file, " },\n");
}