Fix thumbnails sometimes not being resized in the save browser
This was because ImageRequest::Finish used its Width and Height members after calling Request::Finish, after which the ImageRequest object may get deleted at any time by RequestManager. One solution to this is to copy (or preferably move) important members to local variables in the Finish functions of objects derived from Request and use only those after calling Request::Finish (or anything that in turn calls that).
This commit is contained in:
parent
5916c9db9c
commit
341e75cdfe
@ -20,6 +20,9 @@ namespace http
|
||||
try
|
||||
{
|
||||
ByteString data = Request::Finish(&result.status);
|
||||
// Note that at this point it's not safe to use any member of the
|
||||
// APIRequest object as Request::Finish signals RequestManager
|
||||
// to delete it.
|
||||
Client::Ref().ParseServerReturn(data, result.status, true);
|
||||
if (result.status == 200 && data.size())
|
||||
{
|
||||
|
@ -15,6 +15,9 @@ namespace http
|
||||
{
|
||||
std::unique_ptr<UserInfo> user_info;
|
||||
auto result = APIRequest::Finish();
|
||||
// Note that at this point it's not safe to use any member of the
|
||||
// GetUserInfoRequest object as Request::Finish signals RequestManager
|
||||
// to delete it.
|
||||
if (result.document)
|
||||
{
|
||||
auto &user = (*result.document)["User"];
|
||||
|
@ -19,7 +19,12 @@ namespace http
|
||||
|
||||
std::unique_ptr<VideoBuffer> ImageRequest::Finish()
|
||||
{
|
||||
int width = Width;
|
||||
int height = Height;
|
||||
ByteString data = Request::Finish(nullptr);
|
||||
// Note that at this point it's not safe to use any member of the
|
||||
// ImageRequest object as Request::Finish signals RequestManager
|
||||
// to delete it.
|
||||
std::unique_ptr<VideoBuffer> vb;
|
||||
if (data.size())
|
||||
{
|
||||
@ -35,7 +40,7 @@ namespace http
|
||||
vb = std::unique_ptr<VideoBuffer>(new VideoBuffer(32, 32));
|
||||
vb->SetCharacter(14, 14, 'x', 255, 255, 255, 255);
|
||||
}
|
||||
vb->Resize(Width, Height, true);
|
||||
vb->Resize(width, height, true);
|
||||
}
|
||||
return vb;
|
||||
}
|
||||
|
@ -18,6 +18,9 @@ namespace http
|
||||
bool SaveUserInfoRequest::Finish()
|
||||
{
|
||||
auto result = APIRequest::Finish();
|
||||
// Note that at this point it's not safe to use any member of the
|
||||
// SaveUserInfoRequest object as Request::Finish signals RequestManager
|
||||
// to delete it.
|
||||
if (result.document)
|
||||
{
|
||||
return (*result.document)["Status"].asInt() == 1;
|
||||
|
Loading…
Reference in New Issue
Block a user