mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-15 21:15:52 +08:00
Cancelling "fix by netfabb" may leave output file handler to a temp file
opened. This is fixed now. Fixes Memory leak when exporting to netfabb and cancelling #7632
This commit is contained in:
parent
b5c45762c9
commit
3aad2a9f4a
@ -284,29 +284,32 @@ void fix_model_by_win10_sdk(const std::string &path_src, const std::string &path
|
|||||||
|
|
||||||
// Open the destination file.
|
// Open the destination file.
|
||||||
FILE *fout = boost::nowide::fopen(path_dst.c_str(), "wb");
|
FILE *fout = boost::nowide::fopen(path_dst.c_str(), "wb");
|
||||||
|
try {
|
||||||
Microsoft::WRL::ComPtr<ABI::Windows::Storage::Streams::IBuffer> buffer;
|
Microsoft::WRL::ComPtr<ABI::Windows::Storage::Streams::IBuffer> buffer;
|
||||||
byte *buffer_ptr;
|
byte *buffer_ptr;
|
||||||
bufferFactory->Create(65536 * 2048, buffer.GetAddressOf());
|
bufferFactory->Create(65536 * 2048, buffer.GetAddressOf());
|
||||||
{
|
{
|
||||||
Microsoft::WRL::ComPtr<Windows::Storage::Streams::IBufferByteAccess> bufferByteAccess;
|
Microsoft::WRL::ComPtr<Windows::Storage::Streams::IBufferByteAccess> bufferByteAccess;
|
||||||
buffer.As(&bufferByteAccess);
|
buffer.As(&bufferByteAccess);
|
||||||
hr = bufferByteAccess->Buffer(&buffer_ptr);
|
hr = bufferByteAccess->Buffer(&buffer_ptr);
|
||||||
}
|
}
|
||||||
uint32_t length;
|
uint32_t length;
|
||||||
hr = buffer->get_Length(&length);
|
|
||||||
|
|
||||||
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IAsyncOperationWithProgress<ABI::Windows::Storage::Streams::IBuffer*, UINT32>> asyncRead;
|
|
||||||
for (;;) {
|
|
||||||
hr = inputStream->ReadAsync(buffer.Get(), 65536 * 2048, ABI::Windows::Storage::Streams::InputStreamOptions_ReadAhead, asyncRead.GetAddressOf());
|
|
||||||
status = winrt_async_await(asyncRead, throw_on_cancel);
|
|
||||||
if (status != AsyncStatus::Completed)
|
|
||||||
throw Slic3r::RuntimeError(L("Saving mesh into the 3MF container failed."));
|
|
||||||
hr = buffer->get_Length(&length);
|
hr = buffer->get_Length(&length);
|
||||||
if (length == 0)
|
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IAsyncOperationWithProgress<ABI::Windows::Storage::Streams::IBuffer*, UINT32>> asyncRead;
|
||||||
break;
|
for (;;) {
|
||||||
fwrite(buffer_ptr, length, 1, fout);
|
hr = inputStream->ReadAsync(buffer.Get(), 65536 * 2048, ABI::Windows::Storage::Streams::InputStreamOptions_ReadAhead, asyncRead.GetAddressOf());
|
||||||
}
|
status = winrt_async_await(asyncRead, throw_on_cancel);
|
||||||
|
if (status != AsyncStatus::Completed)
|
||||||
|
throw Slic3r::RuntimeError(L("Saving mesh into the 3MF container failed."));
|
||||||
|
hr = buffer->get_Length(&length);
|
||||||
|
if (length == 0)
|
||||||
|
break;
|
||||||
|
fwrite(buffer_ptr, length, 1, fout);
|
||||||
|
}
|
||||||
|
} catch (...) {
|
||||||
|
fclose(fout);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
fclose(fout);
|
fclose(fout);
|
||||||
// Here all the COM objects will be released through the ComPtr destructors.
|
// Here all the COM objects will be released through the ComPtr destructors.
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user