CaptureService bugs and memory leak

Hello! I’ve been recently experimenting with CaptureService, specifically CaptureScreenshot() for some post-processing effects roblox lacks. However, I ran into some odd issues.

this video will showcase my following points: https://youtu.be/LU8PZvRCGTo
game showcase (uncopylocked): CaptureService bug - Roblox

  1. The most important issue: Screenshots never seem to be cleared out of memory, even if nothing references them. Memory seems to rise until the script is deleted, and it never seems to go back down either, leading to a memory leak. This will affect any experience using this API. I could be wrong and it just takes a while, but i am sure that at least 1 gc cycle ran between the recordings.
  2. Framerate seems inconsistent between studio and the client. In studio, i can get 60 fps, but when i play in roblox, i can barely reach 15, along with the captures going out of sync, and taking way longer. i have tested this on a different device and the same exact thing happens. While this issue only impacts you if you’re taking a capture every frame, this inconsistency is really odd and i do think there’s more going on.
  3. Calling CaptureScreenshot() twice within a frame will break it and you have to restart studio for it to work again.
  4. It is very unclear when you can call CaptureScreenshot(), and if you do it wrong, it either will not run or problem 3 will happen. What i did was have a while loop and have RunService.PostSimulation:Wait() yield, which seems to work.

Bonus: there’s a function documented called “TakeCapture” with no info, and when you run it, it throws an error, saying that “it’s not implemented”.

While i am aware that this function was not made for stuff like this, some issues are present in completely normal uses of it. plus, i, and a lot of devs, would REALLY appreciate being able to use it like this, because this feature along with editable images could create some really cool effects that were not possible before!
another thing i’ve noticed is that the client seems to freeze whenever CaptureScreenshot() is called, i’m not sure if it has to do with the fact i am calling it every frame because that’s still just one call per frame. It also seems that the cpu response time spikes from 30ms to 130ms every few frames (as per the performance stats, “cpu response time” might not be an accurate term)
In fact, i took a video of it on my phone and it’s more visible that it slows down at a specific point

here is the code too, i didn’t finish this since i ran into the engine limitations, so it probably isn’t that great.

local cs = game:GetService("CaptureService")
local rs = game:GetService("RunService")
local isbuffer = false
while true do
	local b = os.clock()
	rs.PostSimulation:Wait()
	cs:CaptureScreenshot(function(id)
		if isbuffer then
			isbuffer = false
			script.Parent.ChromaticAberrationBuffer.Image = id
		else
			isbuffer = true
			script.Parent.ChromaticAberration.Image = id
		end
		print(os.clock()-b)
	end)
end

Expected behavior

I expect screenshots to be cleared out of memory, or at least have a method to delete them if they are no longer being referenced, and i also expect for the framerate to be consistent between Studio and the Roblox Client.

Actual behavior

memory keeps climbing with no sign of decreasing
the game performs significantly worse in the client compared to roblox studio.

5 Likes

Bumping.
I found out that if you call the CaptureScreenshot method very often, it “breaks” after it creates a capture in Roblox “Captures” somehow, even though it shouldn’t.

1 Like

yep. i’ve noticed this happen too sometimes. it’s really weird. also i decided to scrap the effect idea and i repurposed it into another effect (and it still suffers from the awkward pause which kinda sucks) (warning loud)

also sometimes keyword sometimes) it seems to just never take a capture so i had to add a timeout which is really stupid.