Page MenuHomeFeedback Tracker

Class Array - Invalid Data Causes Hard Crash
Need More Info, UrgentPublic

Description

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.

Details

Severity
Crash
Resolution
Open
Reproducibility
Always
Operating System
Windows 7 x64
Category
General
Steps To Reproduce

Package the above code into a mod or unpack the zipped version, press the L key -> Game will instantly crash with "DayZ has stopped working"

Event Timeline

Geez changed the task status from New to Assigned.Oct 21 2019, 12:52 PM
Geez added a subscriber: Geez.EditedOct 21 2019, 1:12 PM

Hello CptCookie.
Can you please try the following?

  1. declaring an array of specific types, ref array<Person> people;
  2. creating an instance of the 'people' array in the class constructor, i.e.
class PeopleMachine
{
    ref TClassArray people;
    
    void PeopleMachine()
    {
        people = new TClassArray;
        ...
    }
}

Regards,
Geez

CptCookie added a comment.EditedOct 21 2019, 2:27 PM

Still nothing. I thought I would try all possible configurations of what you suggested, for both specific types array, and a general TClassArray. None of them have the classes stored within the array when trying to access again. Specific types array returns null in all values in the array which doesn't cause the crash (as I can just filter for null as expected). The TClassArray gets messed up the most, showing some values as array<float> and some as INVALID. Trying to access any of this data will hard crash the game (The thread tried to read from or write to a virtual address for which it does not have the appropriate access). In both cases the classes that should be stored are wiped/not saved it seems?

Geez changed the task status from Assigned to Need More Info.Oct 30 2019, 11:34 AM

Hello again CptCookie.
According to the developers, the issue you are describing is not a bug as it is caused by using

TClassArray instead of array<Person>

TClassArray is array of non-managed objects, VM can't guarantee this array will point to valid objects thus prevent crash. With array<Person> it is array of managed objects (Person) and VM can handle it correctly without hard crashes.

Can you please try to use it as described and let us know if you are still experiencing the crash?
Regards,
Geez

Hi Geez,

As I said above. Using the specific types array does avoid the crash, BUT the array is null in all values. (Screenshot above from last time). Its not storing/saving any of the values in the array.

This comment was removed by Geez.

Maybe try
ref array<ref Person> personarray = new array<ref Person>