I have a piece of code I am debugging in a RunService.RenderStepped callback. I have set a conditional breakpoint in one part of this function, and then am stepping through the code with F10.
This bug occurred to me twice in the same test session, so it is pretty frequent and annoying. I don’t know how it behaves with multiple breakpoints in play or if it happens outside of RenderStepped.
It seems to be easy to reproduce, just run this code and set a conditional breakpoint on Line 3 for some value of Index.
game:GetService("RunService").RenderStepped:Connect(function()
for Index = 1, 1000 do
print(Index)
end
end)
You will then get nonsensical results such as:
This behaviour is really problematic when you’re trying to debug nontrivial pieces of code.
Old description of issue in a more complicated scenario
First occurrence:
I am trying to debug a 2D BVH. I have prints that display all the steps the algorithm is taking. Each “VISIBLE RECT %d” should only print each number once as it is just a for loop which runs once every frame and prints the index. Similarly, a “RESET” print can only occur directly after a “QUERY %d” print. So any violation of either of those indicates an issue with how the code is being executed.
While stepping through the code, just after doing a “QUERY %d” print, the debugger suddenly teleported me back to the breakpoint (which was right before the “VISIBLE RECT 5” print), effectively starting execution of that codepath again, and then I was teleported back to the original code I was debugging and execution resumed where it left off (doing the “RESET” print).
Note: The conditional breakpoint condition is effectively VISIBLE_RECT_INDEX == 5
. Which explains why it specifically goes back to that number again.
You can see the erroneous code execution highlighted by the red arrow in the screenshot of the output.
Second occurrence:
Again debugging the same code, but this time I have stepped into a function at the end of the loop’s (over “visible rects”) body. While I was stepping through this inner function, I was suddenly teleported back out to the original breakpoint and a few steps later was teleported back to the inner function.