thank you for your detailed explanation - they are invaluable to detect the cause of the problem !!
the situation you mentioned, seems to be the exact reason, why this bug occurs ! You add a thread to the scheduler (regardless of the priority of the function like Scheduler.PROC_MODE.PROC_EARLIEST), while this one is maybe just iterating over the list to which you add the function -> this causes the crash !
I will have a look at it and see if i can create a quick hotfix for the wrapper, which adds some kind of "thread-safe" - Scheduler.AddEventVoid(FunctionName) function - which should prevent this problem !
edit :
I've uploaded a new version of the wrapper : 1.0.2 (big thanks go to DJBMASTER for providing me with the needed details to solve this problem !!), that now includes a method named AddEventVoidThreadSafe that is the thread safe variant of the method AddEventVoid !
Whenever you don't need AddEventVoidThreadSafe, use AddEventVoid, as methods added through AddEventVoidThreadSafe aren't executed immediately, but may take up to one frame to execute - so only use AddEventVoidThreadSafe if you access the scheduler from another thread !
I've used the following code to test this new function :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using AcknexWrapper;
using System.Threading;
namespace OldWrapperTestApp
{
class Program
{
private static DateTime StartTime = DateTime.Now;
static IEnumerable bla()
{
yield return 1;
}
static void dummyFun()
{
Thread.Sleep(1000);
while (true)
{
Console.WriteLine(DateTime.Now - StartTime);
Scheduler.AddEventVoidThreadSafe(bla);
//Scheduler.AddEventVoid(bla);
Thread.Sleep(2);
}
}
static void Main(string[] args)
{
EngFun.engine_open(null);
EngFun.level_load(null);
Thread t = new Thread(dummyFun);
t.Start();
Scheduler.StartScheduler(bla);
}
}
}
and I've got the following results :
AddEventVoid
1.) 00:00:16.4375000 - crash
2.) 00:00:40.8750000 - crash
3.) 00:00:04.4375000 - crash
4.) 00:00:04.2968750 - crash
5.) 00:06:12.2968750 - crash
6.) 00:00:03.3750000 - crash
7.) 00:00:45.0781250 - crash
8.) 00:00:05.2968750 - crash
9.) 00:00:07.7031250 - crash
10.) 00:00:14.4687500 - crash
AddEventVoidThreadSafe
1.) ~ 00:02:30 - aborted by user - no crash
2.) ~ 00:02:45 - aborted by user - no crash
3.) ~ 00:02:30 - aborted by user - no crash
4.) ~ 00:03:00 - aborted by user - no crash
5.) ~ 00:02:30 - aborted by user - no crash