Skip to content

Commit

Permalink
In rare cases CefStreamReader::CreateForFile returns null - rather th…
Browse files Browse the repository at this point in the history
…an causing a hard crash, log the error and return NULL
  • Loading branch information
amaitland committed May 8, 2017
1 parent 16dbb10 commit c8d0127
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
14 changes: 13 additions & 1 deletion CefSharp.Core/Internals/ClientAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,19 @@ namespace CefSharp
{
auto resourceHandler = static_cast<FileResourceHandler^>(handler);

return new CefStreamResourceHandler(StringUtils::ToNative(resourceHandler->MimeType), CefStreamReader::CreateForFile(StringUtils::ToNative(resourceHandler->FilePath)));
auto streamReader = CefStreamReader::CreateForFile(StringUtils::ToNative(resourceHandler->FilePath));

if (streamReader.get())
{
return new CefStreamResourceHandler(StringUtils::ToNative(resourceHandler->MimeType), streamReader);
}
else
{
auto msg = "Unable to load resource CefStreamReader::CreateForFile returned NULL for file:" + resourceHandler->FilePath;
LOG(ERROR) << StringUtils::ToNative(msg).ToString();

return NULL;
}
}
else if (handler->GetType() == ByteArrayResourceHandler::typeid)
{
Expand Down
14 changes: 13 additions & 1 deletion CefSharp.Core/SchemeHandlerFactoryWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,19 @@ namespace CefSharp
{
auto resourceHandler = static_cast<FileResourceHandler^>(handler);

return new CefStreamResourceHandler(StringUtils::ToNative(resourceHandler->MimeType), CefStreamReader::CreateForFile(StringUtils::ToNative(resourceHandler->FilePath)));
auto streamReader = CefStreamReader::CreateForFile(StringUtils::ToNative(resourceHandler->FilePath));

if (streamReader.get())
{
return new CefStreamResourceHandler(StringUtils::ToNative(resourceHandler->MimeType), streamReader);
}
else
{
auto msg = "Unable to load resource CefStreamReader::CreateForFile returned NULL for file:" + resourceHandler->FilePath;
LOG(ERROR) << StringUtils::ToNative(msg).ToString();

return NULL;
}
}
else if (handler->GetType() == ByteArrayResourceHandler::typeid)
{
Expand Down

0 comments on commit c8d0127

Please sign in to comment.