Skip to content

Commit

Permalink
Merge pull request #84 from CommitteeOfZero/cclcc/fix-videos-and-sysm…
Browse files Browse the repository at this point in the history
…esbox

cclcc/fix-videos-and-sysmesbox: check on empty message in sysmesbox, …
  • Loading branch information
Enorovan authored Oct 31, 2024
2 parents 368a3ff + 2251f62 commit 1ffe37d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
24 changes: 14 additions & 10 deletions src/games/cc/sysmesbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,14 @@ void SysMesBox::AddMessage(uint8_t* str) {
TextLayoutPlainLine(&dummy, 255, Profile::Dialogue::DialogueFont,
TextFontSize, Profile::Dialogue::ColorTable[0], 1.0f,
glm::vec2(TextX, 0.0f), TextAlignment::Left);
float mesLen = 0.0f;
for (int i = 0; i < Messages[MessageCount].size(); i++) {
mesLen += Messages[MessageCount][i].DestRect.Width;
if (!Messages[MessageCount].empty()) {
float mesLen = 0.0f;
for (int i = 0; i < Messages[MessageCount].size(); i++) {
mesLen += Messages[MessageCount][i].DestRect.Width;
}
MessageWidths[MessageCount] = mesLen;
MessageCount++;
}
MessageWidths[MessageCount] = mesLen;
MessageCount++;
}

void SysMesBox::AddChoice(uint8_t* str) {
Expand All @@ -247,12 +249,14 @@ void SysMesBox::AddChoice(uint8_t* str) {
TextLayoutPlainLine(&dummy, 255, Profile::Dialogue::DialogueFont,
TextFontSize, Profile::Dialogue::ColorTable[0], 1.0f,
glm::vec2(TextX, 0.0f), TextAlignment::Left);
float mesLen = 0.0f;
for (int i = 0; i < Choices[ChoiceCount].size(); i++) {
mesLen += Choices[ChoiceCount][i].DestRect.Width;
if (!Choices[ChoiceCount].empty()) {
float mesLen = 0.0f;
for (int i = 0; i < Choices[ChoiceCount].size(); i++) {
mesLen += Choices[ChoiceCount][i].DestRect.Width;
}
ChoiceWidths[ChoiceCount] = mesLen;
ChoiceCount++;
}
ChoiceWidths[ChoiceCount] = mesLen;
ChoiceCount++;
}

} // namespace CC
Expand Down
16 changes: 8 additions & 8 deletions src/io/physicalfilestream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,22 @@ IoError PhysicalFileStream::Create(std::string const& fileName, Stream** out,

int64_t PhysicalFileStream::Read(void* buffer, int64_t sz) {
if (sz < 0 || !(Flags & READ)) return IoError_Fail;
if (Position >= Meta.Size || FileStream.eof()) {
FileStream.clear(FileStream.rdstate() & ~std::ios::failbit &
~std::ios::eofbit); // Clear only failbit and eofbit
return IoError_Eof;
};
if (Position >= Meta.Size) return IoError_Eof;

int bytesToRead = std::min(sz, Meta.Size - Position);
FileStream.read((char*)buffer, bytesToRead);
if (!FileStream) {
auto read = FileStream.gcount();

if (read == 0) { // Check if no data was read
if (FileStream.eof()) return IoError_Eof;
ImpLog(LL_Error, LC_IO, "Read failed for file \"%s\" with error: \"%s\"\n",
SourceFileName.c_str(),
std::generic_category().message(errno).c_str());
FileStream.clear(FileStream.rdstate() & ~std::ios::failbit &
~std::ios::eofbit); // Clear only failbit and eofbit
~std::ios::eofbit);
return IoError_Fail;
}
auto read = FileStream.gcount();

Position += read;
return read;
}
Expand Down

0 comments on commit 1ffe37d

Please sign in to comment.