diff --git a/cocos/base/ccUtils.cpp b/cocos/base/ccUtils.cpp index e8c35c5a72..8977e345be 100644 --- a/cocos/base/ccUtils.cpp +++ b/cocos/base/ccUtils.cpp @@ -88,23 +88,18 @@ void captureScreen(std::function)> imageCallback) auto renderer = director->getRenderer(); auto eventDispatcher = director->getEventDispatcher(); - s_captureScreenCommand.init((std::numeric_limits::max)()); - s_captureScreenCommand.func = [=]{ - renderer->readPixels(nullptr, [=](const backend::PixelBufferDescriptor& pbd) { - if(pbd) { - auto image = utils::makeInstance(&Image::initWithRawData, pbd._data.getBytes(), pbd._data.getSize(), pbd._width, pbd._height, 8, false); - imageCallback(image); - } - else imageCallback(nullptr); - }); - }; - s_captureScreenListener = eventDispatcher->addCustomEventListener(Director::EVENT_AFTER_DRAW, [=](EventCustom* /*event*/) { eventDispatcher->removeEventListener(s_captureScreenListener); s_captureScreenListener = nullptr; - - renderer->addCommand(&s_captureScreenCommand); - renderer->render(); + + // !!!GL: AFTER_DRAW and BEFORE_END_FRAME + renderer->readPixels(nullptr, [=](const backend::PixelBufferDescriptor& pbd) { + if (pbd) { + auto image = utils::makeInstance(&Image::initWithRawData, pbd._data.getBytes(), pbd._data.getSize(), pbd._width, pbd._height, 8, false); + imageCallback(image); + } + else imageCallback(nullptr); + }); }); }