Rewrite asset file loading for new toolchain

Old implementation throws null dereference errors on new toolchain. New implementation has not been fully stress-tested but should be mostly operational.
This commit is contained in:
taylorthemushroom 2023-09-24 23:06:23 -04:00
parent 68eb40b99c
commit 5432664f77

View File

@ -14,10 +14,11 @@
// Read Asset File
static AppPlatform_readAssetFile_return_value AppPlatform_readAssetFile_injection(__attribute__((unused)) unsigned char *app_platform, std::string const& path) {
// Read File
std::string full_path("data/");
full_path.append(path);
std::ifstream stream(full_path);
std::string str((std::istreambuf_iterator<char>(stream)), std::istreambuf_iterator<char>());
std::ifstream stream("data/" + path, std::ios_base::binary | std::ios_base::ate);
long len = stream.tellg();
char *buf = new char[len];
stream.seekg(0, stream.beg);
stream.read(buf, len);
// Return String
AppPlatform_readAssetFile_return_value ret;
ret.length = str.length();