Skip to content

Fix FBX export race conditions#6

Open
robslove wants to merge 1 commit into
Razviar:mainfrom
robslove:fix-fbx-exportlock
Open

Fix FBX export race conditions#6
robslove wants to merge 1 commit into
Razviar:mainfrom
robslove:fix-fbx-exportlock

Conversation

@robslove

@robslove robslove commented Jun 3, 2026

Copy link
Copy Markdown

• Added a global lock in Fbx.cs (Export(string, IImported, ExportOptions)) to serialize FBX export execution.
• Wrapped working-directory switching with try/finally to always restore the previous directory.
Why
• FBX export was running from parallel callers while using Directory.SetCurrentDirectory(...) (process-wide state), causing race conditions.
• This reduces native FBX initialization/export instability (AccessViolationException) seen during concurrent exports.

Copilot AI review requested due to automatic review settings June 3, 2026 08:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds synchronization and safer working-directory handling around FBX export to avoid cross-thread/process-wide side effects during export.

Changes:

  • Introduced a shared export lock to serialize exports.
  • Wrapped Directory.SetCurrentDirectory(...) usage in try/finally to guarantee restoration of the previous working directory.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

{
public static partial class Fbx
{
private static readonly object ExportLock = new object();
Comment on lines +33 to +60
lock (ExportLock)
{
dir.Create();
}
var file = new FileInfo(path);
var dir = file.Directory;

var currentDir = Directory.GetCurrentDirectory();
Directory.SetCurrentDirectory(dir.FullName);
if (!dir.Exists)
{
dir.Create();
}

var name = Path.GetFileName(path);
var currentDir = Directory.GetCurrentDirectory();
try
{
Directory.SetCurrentDirectory(dir.FullName);

using (var exporter = new FbxExporter(name, imported, exportOptions))
{
exporter.Initialize();
exporter.ExportAll();
}
var name = Path.GetFileName(path);

Directory.SetCurrentDirectory(currentDir);
using (var exporter = new FbxExporter(name, imported, exportOptions))
{
exporter.Initialize();
exporter.ExportAll();
}
}
finally
{
Directory.SetCurrentDirectory(currentDir);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants