Jump to content
Sign in to follow this  
AXEL777

NULL pointer to instance

Recommended Posts

I am view this in script.log:

SCRIPT    (E): NULL pointer to instance
Function: 'Get_State_For_Item'
Stack trace:
$CurrentDir:mpmissions/dayzOffline.chernarusplus/EnScript/Functions_Fixed.c:2036
$CurrentDir:mpmissions/dayzOffline.chernarusplus/EnScript/Functions_Fixed.c:2136
$CurrentDir:mpmissions/dayzOffline.chernarusplus/EnScript/Functions_Fixed.c:1948
$CurrentDir:mpmissions/dayzOffline.chernarusplus/EnScript/Functions_Fixed.c:2210
$CurrentDir:mpmissions/dayzOffline.chernarusplus/EnScript/Functions_Fixed.c:2191

what this is and how fix this?

I am use functions:

void Get_State_For_Item()
{
	... code ...
}

in init.c mpmission. What is wrong???

Edited by AXEL777

Share this post


Link to post
Share on other sites
1 hour ago, colinm9991 said:

What's the code?

in this method:

static string Get_State_For_Item(ItemBase item)
{
	string return_stage_value = "";
	Edible_Base item_to_Edible_Base = Edible_Base.Cast(item);	
	if ((item_to_Edible_Base.IsMeat()) && (item_to_Edible_Base))
	{
		private string temp_ret_zn = "";
		temp_ret_zn = item_to_Edible_Base.GetFoodStageName(item_to_Edible_Base.GetFoodStageType());
		if (temp_ret_zn != "")
		{			
			return_stage_value = temp_ret_zn;
		}
	}
	return return_stage_value;
}

 

Share this post


Link to post
Share on other sites

Swap around the if statement conditions, your logic currently says

IF item_to_Edible_Base is Meat AND item_to_Edible_Base is Not Null

Which has the possibility of checking if a null item IsMeat first before validating that it's actually a valid object.

 

You should first check for null, then if IsMeat, as the && will short-circuit the statement if the first condition is false.

 

See if the issue occurs after that, you could also put diagnostic logging in to see how far the script gets in its execution.

 

Is there a stack trace included in the log which you have omitted, or is it purposely blank?

Edited by colinm9991

Share this post


Link to post
Share on other sites
3 minutes ago, colinm9991 said:

Swap around the if statement conditions, your logic currently says

IF item_to_Edible_Base is Meat AND item_to_Edible_Base is Not Null

Which has the possibility of checking if a null item IsMeat first before validating that it's actually a valid object.

 

You should first check for null, then if IsMeat, as the && will short-circuit the statement if the first condition is false.

 

See if the issue occurs after that, you could also put diagnostic logging in to see how far the script gets in its execution.

 

Is there a stack trace included in the log which you have omitted, or is it purposely blank?

yes, stack trace exist

SCRIPT    (E): NULL pointer to instance
Function: 'Get_State_For_Item'
Stack trace:
$CurrentDir:mpmissions/dayzOffline.chernarusplus/EnScript/Functions_Fixed.c:2036
$CurrentDir:mpmissions/dayzOffline.chernarusplus/EnScript/Functions_Fixed.c:2136
$CurrentDir:mpmissions/dayzOffline.chernarusplus/EnScript/Functions_Fixed.c:1948
$CurrentDir:mpmissions/dayzOffline.chernarusplus/EnScript/Functions_Fixed.c:2210
$CurrentDir:mpmissions/dayzOffline.chernarusplus/EnScript/Functions_Fixed.c:2191

 

Edited by AXEL777

Share this post


Link to post
Share on other sites
4 minutes ago, AXEL777 said:

yes, stack trace exist

Can you update the post with it?

 

We can't debug/help if we don't have enough information about the event.

 

-- Edit:

 

Try the above recommendation please with changes to your script, I can see the stack trace isn't very helpful

Edited by colinm9991
  • Like 1

Share this post


Link to post
Share on other sites
11 minutes ago, colinm9991 said:

Can you update the post with it?

 

yes, updated

Share this post


Link to post
Share on other sites
4 hours ago, colinm9991 said:

 

Try the above recommendation please with changes to your script, I can see the stack trace isn't very helpful

yes, this work, big thanks

  • Like 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×