Fix crash in BLI_mmap.cc on WIN32

Address an issue running blender 5.x on the otoy rndr network
where it crashes when loading a scene.

Reset the file pointer to the beginning of the file
in case we are closing it using the windows file
handle due to failure of reading it with memory map.

This keeps everything consistent for later opening that file again.

Ref !155823
This commit is contained in:
Martin Loga 2026-03-19 20:47:17 +11:00 • committed by Thomas Dinges
parent 96bbff21af
commit 956fd000a2

View file

@ -371,7 +371,12 @@ BLI_mmap_file *BLI_mmap_open(int fd)
static std::atomic_size_t id_counter = 0;
void *memory, *handle = nullptr;
const size_t length = BLI_lseek(fd, 0, SEEK_END);
/* It's important not to use `BLI_lseek` here because in case we fail to use mmap and returning
* nullptr, the calling function is not closing the file using the file descriptor means next
* time the file is read the filepointer is still pointing to the end. This is not an issue for
* blender but it throws off the virtual filesystem when blender is running on the
* render-network. See PR !155823 for details. */
const size_t length = BLI_file_descriptor_size(fd);
if (UNLIKELY(length == size_t(-1))) {
return nullptr;
}