Q:

Capturing an area of the screen with cocos2d::RenderTexture and setVirtualViewport

cocos2d-x version: 3.16
I want to capture an area of my screen, and save it in a PNG file. The best way to do that is to use a RenderTexture, and capturing a specific area should be done with the method setVirtualViewport. The documentation says:

void setVirtualViewport   (
      const Vec2 & rtBegin,
      const Rect & fullRect,
      const Rect & fullViewport 
  )   

Used for grab part of screen to a texture.
Parameters

rtBegin   The position of renderTexture on the fullRect.
fullRect  The total size of screen.
fullViewport  The total viewportSize.

I have the following code, with a design resolution of 1920*1080 (I simplified the code to display it here, and gave the values as constants):
unsigned int SIZE_X = 960;
unsigned int SIZE_Y = 540;
unsigned int POS_X = 100;
unsigned int POS_Y = 100;

RenderTexture* texture = RenderTexture::create(SIZE_X, SIZE_Y);
texture->setVirtualViewport(Vec2(POX_X, POS_Y),
                            Rect(0, 0, 1920, 1080),
                            Rect(0, 0, SIZE_X, SIZE_Y));

texture->begin();
this->visit();
texture->end();

texture->saveToFile("test.png", Image::Format::PNG);

I've tried a lot of different combinations of parameters, but whatever I do, at most the pixels from the rectangle 0, 0, SIZE_X, SIZE_Y are captured, the rest is filled with transparent pixels. Also the offset is wrong (it is affected by the ratio betwwen screen size and captured area, though it shouldn't).
Here is the result of the code above for a mockup scene, where red means transparent pixel:

All the pixels that I have displayed in red are empty and they shouldn't, and the offset is wrong: (50, 50) instead of (100, 100).
Do you know how to properly use setVirtualViewport? Is there a bug in their method or am I doing something wrong?
Alternately, do you have another solution to capture an area of the screen and save it into an image or a cocos2d::Sprite? (without moving the content of the Scene)

A:

Since I don't seem to get exactly how the function setVirtualViewport works, or there's maybe a problem with this function, here is a solution I came up with, which does the same thing, even though it's probably not as efficient:

Capture the whole screen in a RenderTexture.
Change the position of the Sprite which is generated by the RenderTexture, even though it doesn't belong to the scene so isn't visible, to put it the beginning of the zone that you want at (0,0).
Create a second RenderTexture of the size that you want to capture.
Visit the sprite to render it in the second RenderTexture.

Here is the code:
unsigned int SIZE_X = 960;
unsigned int SIZE_Y = 540;
unsigned int POS_X = 100;
unsigned int POS_Y = 100;

RenderTexture* screenCapture = RenderTexture::create(1920, 1080);

screenCapture->begin();
this->visit();
screenCapture->end();

RenderTexture* areaTexture = RenderTexture::create(SIZE_X, SIZE_Y);
areaTexture->begin();
screenCapture->getSprite()->setPosition(Vec2(960 - POS_X, 540 - POS_Y));
screenCapture->getSprite()->visit();
areaTexture->end();

AreaTexture->saveToFile("test.png", Image::Format::PNG);

