refactor: file_getfilebuffer → file_readfile (std::vector<char>) — elimina 3 leaks (paleta + música gameplay + música cinemàtica)
This commit is contained in:
@@ -62,15 +62,13 @@ auto Text::nextCodepoint(const char*& ptr) -> uint32_t {
|
||||
// --- Càrrega de font ---
|
||||
|
||||
void Text::loadFont(const char* fnt_file) {
|
||||
int filesize = 0;
|
||||
char* buffer = file_getfilebuffer(fnt_file, filesize, true);
|
||||
if (!buffer) {
|
||||
auto buffer = file_readfile(fnt_file);
|
||||
if (buffer.empty()) {
|
||||
std::cerr << "Text: unable to load font file: " << fnt_file << '\n';
|
||||
return;
|
||||
}
|
||||
|
||||
std::istringstream stream(std::string(buffer, filesize));
|
||||
free(buffer);
|
||||
std::istringstream stream(std::string(buffer.data(), buffer.size()));
|
||||
|
||||
std::string line;
|
||||
int glyph_index = 0;
|
||||
@@ -128,15 +126,14 @@ void Text::loadFont(const char* fnt_file) {
|
||||
}
|
||||
|
||||
void Text::loadBitmap(const char* gif_file) {
|
||||
int filesize = 0;
|
||||
char* buffer = file_getfilebuffer(gif_file, filesize);
|
||||
if (!buffer) {
|
||||
auto buffer = file_readfile(gif_file);
|
||||
if (buffer.empty()) {
|
||||
std::cerr << "Text: unable to load bitmap: " << gif_file << '\n';
|
||||
return;
|
||||
}
|
||||
|
||||
// Extrau dimensions del header GIF (bytes 6-7 = width, 8-9 = height, little-endian)
|
||||
auto* raw = reinterpret_cast<unsigned char*>(buffer);
|
||||
auto* raw = reinterpret_cast<unsigned char*>(buffer.data());
|
||||
int w = raw[6] | (raw[7] << 8);
|
||||
int h = raw[8] | (raw[9] << 8);
|
||||
|
||||
@@ -144,7 +141,6 @@ void Text::loadBitmap(const char* gif_file) {
|
||||
Uint8* pixels = LoadGif(raw, &gw, &gh);
|
||||
if (!pixels) {
|
||||
std::cerr << "Text: unable to decode GIF: " << gif_file << '\n';
|
||||
free(buffer);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -152,7 +148,6 @@ void Text::loadBitmap(const char* gif_file) {
|
||||
bitmap_height_ = h;
|
||||
bitmap_ = pixels;
|
||||
|
||||
free(buffer);
|
||||
std::cout << "Text: bitmap loaded " << w << "x" << h << '\n';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user