Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xrCore: Fix spurious assertion failures in FS::FileDownload for linux #1512

Merged
merged 3 commits into from
Nov 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/xrCore/FS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,25 @@ bool file_handle_internal(pcstr file_name, size_t& size, int& file_handle)

void* FileDownload(pcstr file_name, const int& file_handle, size_t& file_size)
{
VERIFY(file_size != 0);
void* buffer = xr_malloc(file_size);

int r_bytes = _read(file_handle, buffer, file_size);
R_ASSERT3(
// !file_size ||
// (r_bytes && (file_size >= (u32)r_bytes)),
file_size == (u32)r_bytes, "can't read from file : ", file_name);
#ifdef XR_PLATFORM_LINUX
size_t total_r_bytes = 0;
do
{
const ssize_t r_bytes =
_read(file_handle, reinterpret_cast<u8*>(buffer) + total_r_bytes, file_size - total_r_bytes);
R_ASSERT3(r_bytes > 0, "Can't read from file : ", file_name);

total_r_bytes += r_bytes;
} while (total_r_bytes < file_size);
#elif defined(XR_PLATFORM_WINDOWS) || defined(XR_PLATFORM_BSD) || defined(XR_PLATFORM_APPLE)
int total_r_bytes = _read(file_handle, buffer, file_size);
#else
# error Select or add implementation for your platform
#endif
R_ASSERT3(total_r_bytes == file_size, "Can't read from file : ", file_name);

// file_size = r_bytes;

Expand Down