Skip to content

Commit

Permalink
xrCore: Fix spurious assertion failures in FS::FileDownload for lin…
Browse files Browse the repository at this point in the history
…ux (#1512)
  • Loading branch information
AMS21 authored Nov 12, 2023
1 parent e8cb6c4 commit 8ef4317
Showing 1 changed file with 17 additions and 5 deletions.
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

0 comments on commit 8ef4317

Please sign in to comment.