I am working on a game using cocos2d-x 3.1.1 + Lua, for Android. But that game crash when sharing screenshot. Below are some code snippets:
-- take screenshot using Lua
--
local size = cc.Director:getInstance():getVisibleSize()
local texture = cc.RenderTexture:create(size.width, size.height)
texture:setPosition(size.width / 2, size.height / 2)
texture:begin()
cc.Director:getInstance():getRunningScene():visit()
texture:endToLua()
texture:saveToFile(filename, cc.IMAGE_FORMAT_PNG)
Then I send the file to Java via LuaJavaBridge. Java code do below things:
Copy the image from private folder to sdcard
creates an Intent of ACTION_SEND from the copied image, and call startActivity()
I upload the apk to phone. When I tap the share button, a share chooser dialog pops up. Then I tap Cancel to dismiss the dialog, app crashes and go back to desktop.
Some facts may help to locate issue:
Screenshot is taken correctly. I can see the screenshot file in sdcard.
I can share if comment out above Lua code, which is used to take screenshot.
I use the lua-tests/NewEventDispatcher/PauseResumeTargetTest to check this,I insert the following code in the ‘popup’ funciton:
local size = cc.Director:getInstance():getVisibleSize()
local texture = cc.RenderTexture:create(size.width, size.height)
texture:setPosition(size.width / 2, size.height / 2)
texture:begin()
cc.Director:getInstance():getRunningScene():visit()
texture:endToLua()
texture:saveToFile("image-0.png", cc.IMAGE_FORMAT_PNG)
Then, I tap Popup to pop up a layer,then i tap close to exit layer.The test didn’t crash,can you pasts more codes?
And, The v3.2 add the CaptureScreenTest,you can also refer to it.