fixes per a windows: CRLF en parsers de text i SPV de postfx

This commit is contained in:
2026-05-14 13:17:46 +02:00
parent 6bdb5c207c
commit 6f9bdcbeb6
6 changed files with 314 additions and 752 deletions
+10
View File
@@ -67,10 +67,20 @@ bool Lang::setLang(Uint8 lang) {
std::string line;
int index = 0;
while (std::getline(ss, line)) {
// Normaliza CRLF: en Windows els fitxers es llegeixen en binari i
// getline només talla pel \n, deixant un \r residual que faria que les
// línies en blanc no semblen buides (i sobreescriguen més enllà de
// mTextStrings, corrompent el heap).
if (!line.empty() && line.back() == '\r') {
line.pop_back();
}
// Almacena solo las lineas que no empiezan por # o no esten vacias
const bool test1 = line.substr(0, 1) != "#";
const bool test2 = !line.empty();
if (test1 && test2) {
if (index >= MAX_TEXT_STRINGS) {
break;
}
mTextStrings[index] = line;
index++;
}
+10 -1
View File
@@ -19,7 +19,15 @@ static animatedSprite_t parseAnimationStream(std::istream &file, Texture *textur
if (verbose) {
std::cout << "Animation loaded: " << filename << std::endl;
}
// Normalitza CRLF: fitxers .ani amb terminadors de Windows fan que
// line == "[animation]" no faci match i el parser entri en bucle
// infinit / no carregui cap animació.
auto strip_cr = [](std::string &s) {
if (!s.empty() && s.back() == '\r') s.pop_back();
};
while (std::getline(file, line)) {
strip_cr(line);
if (line == "[animation]") {
animation_t buffer;
buffer.speed = 0;
@@ -29,7 +37,8 @@ static animatedSprite_t parseAnimationStream(std::istream &file, Texture *textur
buffer.completed = false;
do {
std::getline(file, line);
if (!std::getline(file, line)) break;
strip_cr(line);
int pos = line.find("=");
if (pos != (int)line.npos) {
if (line.substr(0, pos) == "name") {
@@ -10357,6 +10357,5 @@ static const uint8_t kcrtpi_frag_spv[] = {
0x38,
0x00,
0x01,
0x00,
};
0x00};
static const size_t kcrtpi_frag_spv_size = 10356;
File diff suppressed because it is too large Load Diff
+3
View File
@@ -101,6 +101,9 @@ void Resource::preloadAll() {
std::vector<std::string> lines;
std::string line;
while (std::getline(ss, line)) {
// Normalitza CRLF perquè loadFromVector compari línies amb literals
// ("[animation]", "[/animation]") sense \r residual.
if (!line.empty() && line.back() == '\r') line.pop_back();
lines.push_back(line);
}
animationLines_[bname] = std::move(lines);
+14 -1
View File
@@ -98,7 +98,16 @@ bool Menu::parseFromStream(std::istream &file, const std::string &filename) {
std::string line;
(void)filename;
// Normalitza CRLF: en Windows els .men es llegeixen en binari (resource
// pack o ifstream sense flag de text) i std::getline només talla pel \n,
// deixant un \r residual. Sense això, "[item]" no fa match i el vector
// d'items queda buit → reset() accedeix a item[0] i crasheja.
auto strip_cr = [](std::string &s) {
if (!s.empty() && s.back() == '\r') s.pop_back();
};
while (std::getline(file, line)) {
strip_cr(line);
if (line == "[item]") {
item_t newItem;
newItem.label = "";
@@ -110,7 +119,8 @@ bool Menu::parseFromStream(std::istream &file, const std::string &filename) {
newItem.line = false;
do {
std::getline(file, line);
if (!std::getline(file, line)) break;
strip_cr(line);
int pos = line.find("=");
if (!setItem(&newItem, line.substr(0, pos), line.substr(pos + 1, line.length()))) {
success = false;
@@ -438,6 +448,9 @@ int Menu::getWidestItem() {
void Menu::reset() {
itemSelected = MENU_NO_OPTION;
selector.index = 0;
if (item.empty()) {
return;
}
selector.originY = selector.targetY = selector.y = item[0].rect.y;
selector.originH = selector.targetH = item[0].rect.h;
selector.moving = false;