diff --git a/Bigfoot/Sources/System/File/MemoryMappedFile.cpp b/Bigfoot/Sources/System/File/MemoryMappedFile.cpp index 8922640..245cdfd 100644 --- a/Bigfoot/Sources/System/File/MemoryMappedFile.cpp +++ b/Bigfoot/Sources/System/File/MemoryMappedFile.cpp @@ -148,9 +148,14 @@ WritableMemoryMappedFile::WritableMemoryMappedFile(const File& p_file, const std m_fileDescriptor = open(path.data(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); CRITICAL_ASSERT(SystemAssertHandler, m_fileDescriptor != -1, "Failed to create file {}", path); - [[maybe_unused]] - const int truncateResult = ftruncate(m_fileDescriptor, static_cast(p_size)); - CRITICAL_ASSERT(SystemAssertHandler, truncateResult == 0, "Failed to size file {}", path); + struct stat fileStat {}; + fstat(m_fileDescriptor, &fileStat); + if (static_cast(fileStat.st_size) < p_size) + { + [[maybe_unused]] + const int truncateResult = ftruncate(m_fileDescriptor, static_cast(p_size)); + CRITICAL_ASSERT(SystemAssertHandler, truncateResult == 0, "Failed to size file {}", path); + } void* const mapped = mmap(nullptr, m_size, PROT_READ | PROT_WRITE, MAP_SHARED, m_fileDescriptor, 0); CRITICAL_ASSERT(SystemAssertHandler, mapped != MAP_FAILED, "Failed to map file {}", path);