It seems that GetMaxMagazineTypeName never checks if the type of a magazine exists. Since this is a native function, the only workarounds are to not use OnDebugSpawn on affected weapons or override SpawnAttachedMagazine so you can use a custom function to get magazine type with max ammo count (example below).
```
TStringArray GetMagazineTypesValidated()
{
auto magazines = new TStringArray;
ConfigGetTextArray("magazines", magazines);
auto magazinesValidated = new TStringArray;
foreach (string magazine: magazines)
{
if (GetGame().ConfigIsExisting("CfgMagazines " + magazine))
magazinesValidated.Insert(magazine);
}
return magazinesValidated;
}
string CustomGetMaxMagazineTypeName(int muzzleIndex)
{
auto magazines = GetMagazineTypesValidated();
int max;
string magazineType;
foreach (string magazine: magazines)
{
int count = GetGame().ConfigGetInt("CfgMagazines " + magazine + " count");
if (count > max)
magazineType = magazine;
}
return magazineType;
}
```