sir loin
sir loin
CC#
Created by sir loin on 12/10/2023 in #help
✅ weird transparent areas when using GraphicsPath to draw a string
No description
2 replies
CC#
Created by sir loin on 12/2/2023 in #help
Weird Access violation (no exception) when using StreamReader
internal static IEnumerable<Object3d> CreateModel(string path, string spritePath, uint startTime)
{
using var archive = ZipFile.OpenRead(Paths.AssetArchive);
using StreamReader read = new(archive.GetEntry(path).Open());

List<Vector3> vertices = [];

string line;
while ((line = read.ReadLine()) is not null)
{
var values = line.Trim().Split(' ');
if (values[0].Equals("v")) vertices.Add(new(float.Parse(values[1]), -float.Parse(values[3]), float.Parse(values[2])));
else if (values[0].Equals("f"))
{
List<Vector3> faceVertices = [];
for (var i = 1; i < values.Length; ++i) faceVertices.Add(vertices[int.Parse(values[i].Split('/')[0]) - 1]);

for (var i = 1; i <= faceVertices.Count; ++i)
{
Line3d sprite = new()
{
SpritePath = spritePath,
UseDistanceFade = false
};

sprite.StartPosition.Add(startTime, faceVertices[i == faceVertices.Count ? 0 : i]);
sprite.EndPosition.Add(startTime, faceVertices[i - 1]);
sprite.Thickness.Add(startTime, 2);

yield return sprite;
}
}
}
}
internal static IEnumerable<Object3d> CreateModel(string path, string spritePath, uint startTime)
{
using var archive = ZipFile.OpenRead(Paths.AssetArchive);
using StreamReader read = new(archive.GetEntry(path).Open());

List<Vector3> vertices = [];

string line;
while ((line = read.ReadLine()) is not null)
{
var values = line.Trim().Split(' ');
if (values[0].Equals("v")) vertices.Add(new(float.Parse(values[1]), -float.Parse(values[3]), float.Parse(values[2])));
else if (values[0].Equals("f"))
{
List<Vector3> faceVertices = [];
for (var i = 1; i < values.Length; ++i) faceVertices.Add(vertices[int.Parse(values[i].Split('/')[0]) - 1]);

for (var i = 1; i <= faceVertices.Count; ++i)
{
Line3d sprite = new()
{
SpritePath = spritePath,
UseDistanceFade = false
};

sprite.StartPosition.Add(startTime, faceVertices[i == faceVertices.Count ? 0 : i]);
sprite.EndPosition.Add(startTime, faceVertices[i - 1]);
sprite.Thickness.Add(startTime, 2);

yield return sprite;
}
}
}
}
I have no idea why reading from this stream and then referencing from the vertices list is causing a memory violation, I need help
26 replies
CC#
Created by sir loin on 11/10/2023 in #help
❔ Migrate AppDomain (.net framework) to AssemblyLoadContext (.net core)
I need help converting this code to the .net core equivalent by using AppDomain here, ensured that the code is running in their own domains. However, by migrating the app to .net core (for MANY reasons), AppDomain becomes unusable. I've heard that using AssemblyLoadContext is the best (native) alternative. How could I migrate properly?
var setup = new AppDomainSetup
{
ApplicationName = $"{Name} {Id}",
ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
DisallowCodeDownload = true,
DisallowPublisherPolicy = true,
DisallowBindingRedirects = true
};

var scriptDomain = AppDomain.CreateDomain(setup.ApplicationName, null, setup, new PermissionSet(PermissionState.Unrestricted));

ScriptProvider<TScript> scriptProvider;
try
{
var scriptProviderHandle = Activator.CreateInstanceFrom(scriptDomain,
typeof(ScriptProvider<TScript>).Assembly.ManifestModule.FullyQualifiedName,
typeof(ScriptProvider<TScript>).FullName);

scriptProvider = (ScriptProvider<TScript>)scriptProviderHandle.Unwrap();
scriptProvider.Initialize(assemblyPath, ScriptTypeName);
}
catch
{
AppDomain.Unload(scriptDomain);
throw;
}

if (appDomain != null)
{
Debug.Print($"{nameof(Scripting)}: Unloading domain {appDomain.FriendlyName}");
AppDomain.Unload(appDomain);
}
appDomain = scriptDomain;

return scriptProvider;
var setup = new AppDomainSetup
{
ApplicationName = $"{Name} {Id}",
ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
DisallowCodeDownload = true,
DisallowPublisherPolicy = true,
DisallowBindingRedirects = true
};

var scriptDomain = AppDomain.CreateDomain(setup.ApplicationName, null, setup, new PermissionSet(PermissionState.Unrestricted));

ScriptProvider<TScript> scriptProvider;
try
{
var scriptProviderHandle = Activator.CreateInstanceFrom(scriptDomain,
typeof(ScriptProvider<TScript>).Assembly.ManifestModule.FullyQualifiedName,
typeof(ScriptProvider<TScript>).FullName);

scriptProvider = (ScriptProvider<TScript>)scriptProviderHandle.Unwrap();
scriptProvider.Initialize(assemblyPath, ScriptTypeName);
}
catch
{
AppDomain.Unload(scriptDomain);
throw;
}

if (appDomain != null)
{
Debug.Print($"{nameof(Scripting)}: Unloading domain {appDomain.FriendlyName}");
AppDomain.Unload(appDomain);
}
appDomain = scriptDomain;

return scriptProvider;
12 replies