RenderTexture and global Z layer issue

I’m having a problem with the following code when the nodes in the scene use global z instead of local z values for layering. The output image is completely blank in this case. If I use local Z values for the nodes, and ensure that global z is 0 for all the elements, then the output image is correct, which shows exactly what is displayed on the screen.

    auto visibleSize = Director::getInstance()->getVisibleSize();
    auto renderTexture = RenderTexture::create(visibleSize.width, visibleSize.height, Texture2D::PixelFormat::RGBA8888);
    if (nullptr == renderTexture)
    {
        return;
    }

    renderTexture->beginWithClear(0, 0, 0, 0);
    Director::getInstance()->getRunningScene()->visit();
    renderTexture->end();
    renderTexture->saveToFile(outputFilename);
    Director::getInstance()->getRenderer()->render();

Does anyone have any insight into why global z usage would cause an issue, or any advice on how to get it working? This was done with 3.17.1 and 3.17.2 using the Win32 build.

If I use the utils::captureScreen(...) function, then the saved file is correct, but I need the RenderTexture method to work for various reasons, one of which being that I want to add an image on top of what is rendered out from the scene to the RenderTexture, before it is saved (like a watermark).

EDIT: Never mind, it seems to be a bug that is yet to be addressed.