fix concurrency issue in interface proxying
This commit is contained in:
parent
735893c1d5
commit
defa1b9a95
|
@ -10,6 +10,7 @@
|
||||||
## Upcoming release
|
## Upcoming release
|
||||||
* For players:
|
* For players:
|
||||||
* Added error message if you manually install the wrong SMAPI bitness (e.g. 32-bit SMAPI with 64-bit game).
|
* Added error message if you manually install the wrong SMAPI bitness (e.g. 32-bit SMAPI with 64-bit game).
|
||||||
|
* Fixed intermittent error if a mod fetches mod-provided APIs asynchronously.
|
||||||
|
|
||||||
## 3.11.0
|
## 3.11.0
|
||||||
Released 09 July 2021 for Stardew Valley 1.5.4 or later. See [release highlights](https://www.patreon.com/posts/53514295).
|
Released 09 July 2021 for Stardew Valley 1.5.4 or later. See [release highlights](https://www.patreon.com/posts/53514295).
|
||||||
|
|
|
@ -36,23 +36,26 @@ namespace StardewModdingAPI.Framework.Reflection
|
||||||
public TInterface CreateProxy<TInterface>(object instance, string sourceModID, string targetModID)
|
public TInterface CreateProxy<TInterface>(object instance, string sourceModID, string targetModID)
|
||||||
where TInterface : class
|
where TInterface : class
|
||||||
{
|
{
|
||||||
// validate
|
lock (this.Builders)
|
||||||
if (instance == null)
|
|
||||||
throw new InvalidOperationException("Can't proxy access to a null API.");
|
|
||||||
if (!typeof(TInterface).IsInterface)
|
|
||||||
throw new InvalidOperationException("The proxy type must be an interface, not a class.");
|
|
||||||
|
|
||||||
// get proxy type
|
|
||||||
Type targetType = instance.GetType();
|
|
||||||
string proxyTypeName = $"StardewModdingAPI.Proxies.From<{sourceModID}_{typeof(TInterface).FullName}>_To<{targetModID}_{targetType.FullName}>";
|
|
||||||
if (!this.Builders.TryGetValue(proxyTypeName, out InterfaceProxyBuilder builder))
|
|
||||||
{
|
{
|
||||||
builder = new InterfaceProxyBuilder(proxyTypeName, this.ModuleBuilder, typeof(TInterface), targetType);
|
// validate
|
||||||
this.Builders[proxyTypeName] = builder;
|
if (instance == null)
|
||||||
}
|
throw new InvalidOperationException("Can't proxy access to a null API.");
|
||||||
|
if (!typeof(TInterface).IsInterface)
|
||||||
|
throw new InvalidOperationException("The proxy type must be an interface, not a class.");
|
||||||
|
|
||||||
// create instance
|
// get proxy type
|
||||||
return (TInterface)builder.CreateInstance(instance);
|
Type targetType = instance.GetType();
|
||||||
|
string proxyTypeName = $"StardewModdingAPI.Proxies.From<{sourceModID}_{typeof(TInterface).FullName}>_To<{targetModID}_{targetType.FullName}>";
|
||||||
|
if (!this.Builders.TryGetValue(proxyTypeName, out InterfaceProxyBuilder builder))
|
||||||
|
{
|
||||||
|
builder = new InterfaceProxyBuilder(proxyTypeName, this.ModuleBuilder, typeof(TInterface), targetType);
|
||||||
|
this.Builders[proxyTypeName] = builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
// create instance
|
||||||
|
return (TInterface)builder.CreateInstance(instance);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue