Studio's Undo can cause CSG to break in a reliable fashion (error code -25)

It’s hard to explain, but here’s a video:

  1. I subtract the yellow part by the red part. This operation is marked with SetWaypoint before and after.
  2. The result is subtracted by the red part using the same code. Like (1), I use SetWaypoint before and after.
  3. I undo in studio.
  4. I run the exact same operation as (2). I reliably get CSG error code -25 every time I try to do an operation involving this new part.
  5. Even studio’s builtin CSG tools fail when operations involving this part is done.

Here’s the code I’m running in the command bar:

game:GetService("ChangeHistoryService"):SetWaypoint("Test")

local A = game.Selection:Get()[1]
local B = game.Selection:Get()[2]

local result = A:SubtractAsync({B})
result.Parent = workspace
game.Selection:Set({result})

game:GetService("ChangeHistoryService"):SetWaypoint("Test")

And here’s a very easy repro. Running this code will reliably cause the error to happen. One interesting thing to note is that removing the :SetWaypoint() call near the end will prevent the error from happening.

local ChangeHistoryService = game:GetService("ChangeHistoryService")
local A = Instance.new("Part", workspace)
local B = Instance.new("Part", workspace)
A.Position = Vector3.new(0, 0, 0)
B.Position = Vector3.new(0, 0.5, 0)

-- Step 1
ChangeHistoryService:SetWaypoint("Test")
local result = A:SubtractAsync({B})
result.Parent = workspace
ChangeHistoryService:SetWaypoint("Test")

-- Step 2
ChangeHistoryService:SetWaypoint("Test")
result:SubtractAsync({B})
ChangeHistoryService:SetWaypoint("Test")

-- Step 3
ChangeHistoryService:Undo()

-- Step 4
-- Interestingly, removing this SetWaypoint call will
-- prevent the error from happening.
ChangeHistoryService:SetWaypoint("Test")
result:SubtractAsync({B}) -- Errors here.
3 Likes

I was able to reproduce using the provided script, and verify that this is fixed in our on-going work to resolve the CSG data loss issue (either error code -25 or disappearing unions).

4 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.