Skip to content

Commit

Permalink
Fix a bug where native is accessed from multithread with UnityRenderer
Browse files Browse the repository at this point in the history
  • Loading branch information
durswd committed Dec 1, 2024
1 parent 827a55e commit f3ab2d9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
9 changes: 6 additions & 3 deletions Dev/Plugin/Assets/Effekseer/Scripts/Effekseer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ internal static class Plugin
[DllImport(pluginName)]
public static extern void EffekseerUpdate(float deltaTime);

[DllImport(pluginName)]
public static extern IntPtr EffekseerGetUpdateStateFunc();

[DllImport(pluginName)]
public static extern IntPtr EffekseerGetRenderFunc(int renderId = 0);

Expand All @@ -108,6 +111,9 @@ internal static class Plugin
[DllImport(pluginName)]
public static extern IntPtr EffekseerGetRenderBackFunc(int renderId = 0);

[DllImport(pluginName)]
public static extern void EffekseerUpdateState(int renderId = 0);

[DllImport(pluginName)]
public static extern void EffekseerRender(int renderId = 0);

Expand All @@ -117,9 +123,6 @@ internal static class Plugin
[DllImport(pluginName)]
public static extern void EffekseerRenderBack(int renderId = 0);

[DllImport(pluginName)]
public static extern IntPtr EffekseerGetUpdateStateFunc();

[DllImport(pluginName)]
public static extern void EffekseerSetProjectionMatrix(int renderId, float[] matrix);

Expand Down
30 changes: 26 additions & 4 deletions Dev/Plugin/Assets/Effekseer/Scripts/EffekseerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,16 @@ public void TermPlugin()

// Finalize Effekseer library
Plugin.EffekseerTerm();
// For a platform that is releasing in render thread
GL.IssuePluginEvent(Plugin.EffekseerGetRenderFunc(), 0);

if (Instance.RendererType == EffekseerRendererType.Native)
{
// For a platform that is releasing in render thread
GL.IssuePluginEvent(Plugin.EffekseerGetRenderFunc(), 0);
}
else
{
Plugin.EffekseerUpdateState(0);
}

Instance = null;
}
Expand Down Expand Up @@ -590,7 +598,14 @@ public void ResetRestTime()

public void UpdateRendererState()
{
GL.IssuePluginEvent(Plugin.EffekseerGetUpdateStateFunc(), 0);
if (Instance.RendererType == EffekseerRendererType.Native)
{
GL.IssuePluginEvent(Plugin.EffekseerGetUpdateStateFunc(), 0);
}
else
{
Plugin.EffekseerUpdateState(0);
}
}
#endif

Expand All @@ -616,7 +631,14 @@ internal void Update(float deltaTime, float unsacaledDeltaTime)

ApplyLightingToNative();

GL.IssuePluginEvent(Plugin.EffekseerGetUpdateStateFunc(), 0);
if (Instance.RendererType == EffekseerRendererType.Native)
{
GL.IssuePluginEvent(Plugin.EffekseerGetUpdateStateFunc(), 0);
}
else
{
Plugin.EffekseerUpdateState(0);
}
}

/// <summary>
Expand Down

0 comments on commit f3ab2d9

Please sign in to comment.