Viewport Frames can mishandle Welds and display its objects incorrectly

Currently viewportframes can misrender welded objects, this appears to be an issue where if you weld too many parts together at once and then immediately parent it to a viewportframe in the same frame, the displayed result will look like a complete mess.

This appears to be a sort of racing condition because sometimes it fails and sometimes it does not. It can also be fixed by adding some arbitrary waits before parenting into the viewportframe. The key factor seems to be waiting before parenting it outside of workspace, it seems like if you go too fast it interrupts some internal calculations and stores data incorrectly?

To quickly add, I’ve tried using simple task.defer and task.wait() to wait an extra frame or two at times, and it appears the time it needs can be more than 1 frame

This is very frustrating as this undefined behaviour makes it extremely difficult to automate viewportframe creations if I have a unknown amount of time I have to wait for all of the welds to settle.

Just for full clarity, here’s what I’m currently doing in my setup sequence:

  1. for loop each car and anchor all their parts
  2. parent all the cars to workspace at position 0,0,0 in workspace
  3. task.wait()
  4. for every car in workspace, find all their connected pieces using workspace:GetPartBoundsInBox and then weld them together
  5. parent back into replicated storage
  6. the gui now initializes and puts the car models in their respective Viewport Frames

Here’s a video showcasing the issue:

And here’s my cutting and pasting the same object back into the viewport frame just to show that it’s simply a render issue

Addendum:
After some testing this appears to be primarily be an issue in step 1, if a part was originally unanchored and I anchored it, it seems to cause this weird chain reaction. The solution is to anchor all the pieces, run task.wait(), then parent them to workspace. The wait in step 3 is no longer necessary

1 Like

Can you attach a minimal repro test case that demonstrates the issue?

this was happening in an older game of mine and i never figured out the cause but the task.wait() just fixed it lol

i’ve sent you a repro file in pms

thanks, I’ve been struggling getting a working repro on my end :sweat_smile:

1 Like

I’ve realized a major error I’ve been doing this whole time. I’ve been initializing the cars on the server at frame 1 while the viewport frames are being initialized on the client at frame 1. Meaning that I was most likely having the client clone models in the middle of being modified by the server.

And I guess it caused the model to be stuck in some invalid state by some freak coincidence in timing?