Page MenuHomeFeedback Tracker

Handling of casts, error in CalculateVisibilityForAI
Assigned, UrgentPublic

Description

Hello. This error has been happening quite a bit for a while, we are getting client logs hogged with this error

NULL pointer to instance
Class:      'SurvivorBase'
Entity id:2951224

Function: 'CalculateVisibilityForAI'
Stack trace:
scripts/4_World/entities\manbase\playerbase.c:4317
scripts/4_World/entities\manbase\playerbase.c:890
MuchStuffPack/MSP_Clothing_Data/scripts/4_World/playerbase.c:5
WindstrideClothing/scripts/4_World/playerbase.c:5
WillowGlade/WG_MedicalAttention/scripts/4_World/entities\manbase\playerbase.c:714

In the modded playerbase, each line points to super.EEItemAttached(item, slot_name);
Problem is when casting the attachment to ClothingBase it's failing. There's no handling if the cast fails which is causing the error. Argument could be that maybe we do need to raise an error if a modded item is setup wrong but i'd rather not have 1.5gb worth of errors in clients logs. From tests it seems it's failing to cast items that are defined as "Clothing_Base" in config, rather than inheriting from "Clothing". Maybe casts should be on Clothing_Base instead? Several possibilities here to sort this out.

Vanilla code:

	void CalculateVisibilityForAI()
	{
		const int VISIBILITY_SLOTS_COUNT = 10;

		int attcount = GetInventory().AttachmentCount();
		float sumVisibility = 0;
		float countVisibility = 0;
		float visibilityMean = 0;

		if (attcount > 0)
		{
			for (int att = 0; att < attcount; att++)
			{
				EntityAI attachment = GetInventory().GetAttachmentFromIndex(att);
				if ( attachment.IsClothing() )
				{
					ClothingBase clothing;
					Class.CastTo(clothing, attachment);
					sumVisibility += clothing.GetItemVisibility();
					countVisibility++;
				}
			}

			visibilityMean = (sumVisibility + (VISIBILITY_SLOTS_COUNT - countVisibility)) / VISIBILITY_SLOTS_COUNT;
			SetVisibilityCoef(visibilityMean);
		}
		else
		{
			visibilityMean = 1;
			SetVisibilityCoef(visibilityMean);
		}
	}

How it should be maybe:

	void CalculateVisibilityForAI()
	{
		const int VISIBILITY_SLOTS_COUNT = 10;

		int attcount = GetInventory().AttachmentCount();
		float sumVisibility = 0;
		float countVisibility = 0;
		float visibilityMean = 0;

		if (attcount > 0)
		{
			for (int att = 0; att < attcount; att++)
			{
				EntityAI attachment = GetInventory().GetAttachmentFromIndex(att);
				if ( attachment.IsClothing() )
				{
					ClothingBase clothing;
                    			if(!Class.CastTo(clothing, attachment))
                        			continue;
					sumVisibility += clothing.GetItemVisibility();
					countVisibility++;
				}
			}

			visibilityMean = (sumVisibility + (VISIBILITY_SLOTS_COUNT - countVisibility)) / VISIBILITY_SLOTS_COUNT;
			SetVisibilityCoef(visibilityMean);
		}
		else
		{
			visibilityMean = 1;
			SetVisibilityCoef(visibilityMean);
		}
	}
	void CalculateVisibilityForAI()
	{
		const int VISIBILITY_SLOTS_COUNT = 10;

		int attcount = GetInventory().AttachmentCount();
		float sumVisibility = 0;
		float countVisibility = 0;
		float visibilityMean = 0;

		if (attcount > 0)
		{
			for (int att = 0; att < attcount; att++)
			{
				EntityAI attachment = GetInventory().GetAttachmentFromIndex(att);
				if ( attachment.IsClothing() )
				{
					Clothing_Base clothing; //Using clothing_base as cast instead?
                    			if(!Class.CastTo(clothing, attachment))
                        			continue;
					sumVisibility += clothing.GetItemVisibility();
					countVisibility++;
				}
			}

			visibilityMean = (sumVisibility + (VISIBILITY_SLOTS_COUNT - countVisibility)) / VISIBILITY_SLOTS_COUNT;
			SetVisibilityCoef(visibilityMean);
		}
		else
		{
			visibilityMean = 1;
			SetVisibilityCoef(visibilityMean);
		}
	}

Details

Severity
Tweak
Resolution
Open
Reproducibility
Sometimes
Operating System
Windows 10
Category
General

Event Timeline

Geez changed the task status from New to Assigned.Thu, Jul 22, 3:31 PM