Run into a nasty crash when trying to access a class within a class array. I made a new test mod / example, to test it and reproduce it. I'm trying to get the first class from the class array and then run that classes functions/access it. Creating a new class instance, and adding it to the array works as expected. But trying to access that class again (from a different module at least) will instantly crash the game/engine with a "Dayz has stopped working". Full code to below. (I'm using the workbench with filepatching, and the diag .exe)
\ModName\scripts\4_World
class Person { private string name; private int age; void Person(string newName, int newAge) { name = newName; age = newAge; } string GetName() { return name; } } class PeopleMachine { ref TClassArray people = new TClassArray; void PeopleMachine() { Person newPerson = new Person("Bob",25); people.Insert(newPerson); Person testPerson = people.Get(0); Print(testPerson.GetName() + " is in the array"); } string GetFirstPersonName() /*<- Crash is triggered here when trying to access the class again*/ { Person testPerson = people.Get(0); if(testPerson) { return testPerson.GetName(); } return "Class Empty"; } } static ref PeopleMachine PeopleClient; static ref PeopleMachine GetPeopleClient() { if ( !PeopleClient ) { PeopleClient = new ref PeopleMachine(); } return PeopleClient; };
\ModName\scripts\5_Mission
modded class MissionGameplay extends MissionBase { void MissionGameplay() { GetPeopleClient(); } override void OnInit() { super.OnInit(); } {F1293963} override void OnKeyPress(int key) { super.OnKeyPress(key); m_Hud.KeyPress(key); if(key == KeyCode.KC_L) { Print(GetPeopleClient().GetFirstPersonName()); } } };
I also have CF and Community Online Tools loaded, though this doesn't have an effect on the crash.
If I've made any logic errors or bad practices let me know. That being said I would expect the game to crash normally with a log and not just instantly die without. Attached below are the mini dump file and I've also zipped the file-patching version of the same code/mod above.