Page MenuHomeFeedback Tracker

"Map" container doesn't store ref counters correctly
Assigned, UrgentPublic

Description

class TestObj {
    string name;
}

modded class MissionGameplay {
    ref map<int, ref TestObj> test_map = new map<int, ref TestObj>();  

    void MissionGameplay() {
        JsonSerializer js = new JsonSerializer();
        string error;
        js.ReadFromString(test_map, "{\"10\": {\"name\": \"abcd\"}}", error);
        foreach(auto key, auto object: test_map)
        {
            Print(key);
            Print(object);
        }
    }

    override void OnUpdate(float timeslice) {
        super.OnUpdate(timeslice);
        foreach(auto key, auto object: test_map)
        {
            Print(key);
            Print(object);
        }
    }
}

Expected behavior:
variable test_map should store all deserialized objects from the string until the map will be destroyed
Logs should be:

-------------(MissionGameplay method)----------------
SCRIPT       : int key =     10
SCRIPT       : TestObj object = TestObj<2b1910e0>

------------------(OnUpdate method)--------------------
SCRIPT       : int key =     10
SCRIPT       : TestObj object = TestObj<2b1910e0>

Actual behavior:
All the TestObj objects are destroyed right after the function MissionGameplay is over

Logs:

-------------(MissionGameplay method)----------------
SCRIPT       : int key =     10
SCRIPT       : TestObj object = TestObj<2b1910e0>

------------------(OnUpdate method)--------------------
SCRIPT       : int key =     10
SCRIPT       : TestObj object = NULL

Details

Severity
Minor
Resolution
Open
Reproducibility
Always
Operating System
Windows 10 x64
Category
General
Steps To Reproduce

Dayz 1.21

  1. Run the code from the example
  2. Check the clientside logs
Additional Information

If I replace map to array (with additional changes for loops and serialized string) everything works as expected

Event Timeline

Geez changed the task status from New to Assigned.Jun 6 2023, 12:51 PM

Any updates on this issue?

lava76 added a subscriber: lava76.Mar 24 2024, 2:06 PM