Skip to content

Instantly share code, notes, and snippets.

@CedricGuillemet
Created September 23, 2020 09:13
Show Gist options
  • Save CedricGuillemet/ba073ebb8b886f46d17216d37179946a to your computer and use it in GitHub Desktop.
Save CedricGuillemet/ba073ebb8b886f46d17216d37179946a to your computer and use it in GitHub Desktop.
arcana::make_task(arcana::threadpool_scheduler, m_cancelSource,
[this, dataSpan, generateMips, invertY, onErrorRef = Napi::Persistent(onError)]() {
try
{
bimg::ImageContainer* image = bimg::imageParse(&m_allocator, dataSpan.data(), static_cast<uint32_t>(dataSpan.size()));
// todo: bimg::imageParse will return nullptr when trying to load a texture with an url that is not a valid texture
// Like a 404 html page.
if (invertY)
{
FlipY(image);
}
if (generateMips)
{
GenerateMips(&m_allocator, &image);
}
return image;
}
catch (const std::exception& /*ex*/)
{
onErrorRef.Call({});
}
bimg::ImageContainer* tmp{};
return tmp;
})
.then(RuntimeScheduler, m_cancelSource, [texture, dataRef = Napi::Persistent(data)](bimg::ImageContainer* image) {
CreateTextureFromImage(texture, image);
})
.then(arcana::inline_scheduler, m_cancelSource, [onSuccessRef = Napi::Persistent(onSuccess), onErrorRef = Napi::Persistent(onError)](arcana::expected<void, std::exception_ptr> result) {
if (result.has_error())
{
onErrorRef.Call({});
}
else
{
onSuccessRef.Call({});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment