The following script can cause some of the objects of “Foo” to be destructed during sorting.
class Bar {}
class Foo
{
int m_i;
Bar@ m_bar; // comment this out to make the problem disappear
Foo(int i) { m_i = i; }
~Foo() { print("dtor " + m_i); }
}
bool SortFunc(const Foo@ &in a, const Foo@ &in b)
{
return b.m_i % 7 == 0;
}
array<Foo@> g_arr;
void Main()
{
print("start of main");
for (int i = 0; i < 500; i++) {
g_arr.InsertLast(Foo(i));
}
g_arr.Sort(SortFunc);
print("end of main");
}
It seems to be due to the existance of m_bar. Changing that to not be a handle (eg. “Bar m_bar”) will make the problem disappear, as well as not calling Sort.
Example output:
[ ScriptEngine] [22:10:20] Loaded 'Plugin_Repro'
[ ScriptRuntime] [22:10:20] start of main
[ ScriptRuntime] [22:10:20] dtor 124
[ ScriptRuntime] [22:10:20] dtor 217
[ ScriptRuntime] [22:10:20] dtor 282
[ ScriptRuntime] [22:10:20] dtor 335
[ ScriptRuntime] [22:10:20] dtor 381
[ ScriptRuntime] [22:10:20] dtor 422
[ ScriptRuntime] [22:10:20] dtor 459
[ ScriptRuntime] [22:10:20] end of main
[ ScriptRuntime] [22:10:20] dtor 494
The indices that it destructs can be different every time. I also find the destructor after “end of main” to be quite odd.
This is using the latest SVN version of Angelscript as well as the latest SVN version of scriptarray (although the function names modified to have capital letters)