NullReferenceException on Entity.Destroy()

Jakkee

Plugin Developer
Plugin Developer
Contributor
Jul 28, 2014
1,465
927
113
Australia
I get NullReferenceException: Object reference not set to an instance of an object when I do Entity.Destroy()
Would post logs but its not showing up in the logs
 

Jakkee

Plugin Developer
Plugin Developer
Contributor
Jul 28, 2014
1,465
927
113
Australia
Which Entity? Foundation, It can be anything?

Also, which Event?
- Destroying Pillar/Foundations
- On_EntityDeployed
Python:
    def On_EntityDeployed(self, Player, Entity):
        if Entity.Name == "WoodPillar":
            for foundation in Entity.GetLinkedStructs():
                if foundation.Name == "WoodFoundation":
                    if round(DataStore.Get("BuildingRestriction", "Max Height"), 0) < Entity.Y - foundation.Y:
                        Entity.Destroy()
                        Player.Inventory.AddItem("Wood Pillar")
                        Player.InventoryNotice("1 x Wood Pillar")
                        Player.Message("You are not allowed to build more than [ " + str(round(DataStore.Get("BuildingRestriction", "Max Height"), 0) / 4) + " ] pillars high")
                break
        elif Entity.Name == "WoodFoundation":
            count = 0
            for foundation in Entity.GetLinkedStructs():
                if foundation.Name == "WoodFoundation":
                    count += 1
                    if count == DataStore.Get("BuildingRestriction", "Max Foundations"):
                        Entity.Destroy()
                        Player.Inventory.AddItem("Wood Foundation")
                        Player.InventoryNotice("1 x Wood Foundation")
                        Player.Message("You are not allowed to place more than [ " + str(DataStore.Get("BuildingRestriction", "Max Foundations")) + " ] foundations")
                        break
                    continue
                continue
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,077
4,749
113
At your house.
github.com
- Destroying Pillar/Foundations
- On_EntityDeployed
Python:
    def On_EntityDeployed(self, Player, Entity):
        if Entity.Name == "WoodPillar":
            for foundation in Entity.GetLinkedStructs():
                if foundation.Name == "WoodFoundation":
                    if round(DataStore.Get("BuildingRestriction", "Max Height"), 0) < Entity.Y - foundation.Y:
                        Entity.Destroy()
                        Player.Inventory.AddItem("Wood Pillar")
                        Player.InventoryNotice("1 x Wood Pillar")
                        Player.Message("You are not allowed to build more than [ " + str(round(DataStore.Get("BuildingRestriction", "Max Height"), 0) / 4) + " ] pillars high")
                break
        elif Entity.Name == "WoodFoundation":
            count = 0
            for foundation in Entity.GetLinkedStructs():
                if foundation.Name == "WoodFoundation":
                    count += 1
                    if count == DataStore.Get("BuildingRestriction", "Max Foundations"):
                        Entity.Destroy()
                        Player.Inventory.AddItem("Wood Foundation")
                        Player.InventoryNotice("1 x Wood Foundation")
                        Player.Message("You are not allowed to place more than [ " + str(DataStore.Get("BuildingRestriction", "Max Foundations")) + " ] foundations")
                        break
                    continue
                continue
If you would put a debug msg after the if round statement would that appear?

Sent from my Samsung Galaxy S4
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,077
4,749
113
At your house.
github.com
- Destroying Pillar/Foundations
- On_EntityDeployed
Python:
    def On_EntityDeployed(self, Player, Entity):
        if Entity.Name == "WoodPillar":
            for foundation in Entity.GetLinkedStructs():
                if foundation.Name == "WoodFoundation":
                    if round(DataStore.Get("BuildingRestriction", "Max Height"), 0) < Entity.Y - foundation.Y:
                        Entity.Destroy()
                        Player.Inventory.AddItem("Wood Pillar")
                        Player.InventoryNotice("1 x Wood Pillar")
                        Player.Message("You are not allowed to build more than [ " + str(round(DataStore.Get("BuildingRestriction", "Max Height"), 0) / 4) + " ] pillars high")
                break
        elif Entity.Name == "WoodFoundation":
            count = 0
            for foundation in Entity.GetLinkedStructs():
                if foundation.Name == "WoodFoundation":
                    count += 1
                    if count == DataStore.Get("BuildingRestriction", "Max Foundations"):
                        Entity.Destroy()
                        Player.Inventory.AddItem("Wood Foundation")
                        Player.InventoryNotice("1 x Wood Foundation")
                        Player.Message("You are not allowed to place more than [ " + str(DataStore.Get("BuildingRestriction", "Max Foundations")) + " ] foundations")
                        break
                    continue
                continue
Can you try this?
Python:
try:
      Entity.Destroy()
except:
      Server.Broadcast("Something is wrong with: " + str(Entity))
      return
 

Jakkee

Plugin Developer
Plugin Developer
Contributor
Jul 28, 2014
1,465
927
113
Australia
Can you try this?
Python:
try:
      Entity.Destroy()
except:
      Server.Broadcast("Something is wrong with: " + str(Entity))
      return
With Entity.Destroy() commented out is it fine. With it in it will still destroy the object but just give the error. It doesn't seem to effect anything, Its just annoying.

Also doing the try: except: still gives the error
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,077
4,749
113
At your house.
github.com
With Entity.Destroy() commented out is it fine. With it in it will still destroy the object but just give the error. It doesn't seem to effect anything, Its just annoying.

Also doing the try: except: still gives the error
If It happens with Try, then It is not the destroy function.

I removed some unnecessary coding stuffs, and changed the structure of the code to help you understand what's continue.

Give it a try.
Python:
def On_EntityDeployed(self, Player, Entity):
    if Entity.Name == "WoodPillar":
        #Entity locations are in float, this is just a case stuff.
        height = round(float(DataStore.Get("BuildingRestriction", "Max Height")), 0)
        for foundation in Entity.GetLinkedStructs():
            if foundation.Name != "WoodFoundation":
                continue
            if height < Entity.Y - foundation.Y:
                try:
                    Entity.Destroy()
                except:
                    Server.Broadcast("Failed to destroy the entity.")
                Player.Inventory.AddItem("Wood Pillar")
                Player.InventoryNotice("1 x Wood Pillar")
                Player.Message("You are not allowed to build more than [ " + str(round(DataStore.Get("BuildingRestriction", "Max Height"), 0) / 4) + " ] pillars high")
                break
    elif Entity.Name == "WoodFoundation":
        count = 0
        max = int(DataStore.Get("BuildingRestriction", "Max Foundations"))
        for foundation in Entity.GetLinkedStructs():
            if foundation.Name != "WoodFoundation":
                continue
            count += 1
            if count == max:
                try:
                    Entity.Destroy()
                except:
                    Server.Broadcast("Failed to destroy the entity.")
                Player.Inventory.AddItem("Wood Foundation")
                Player.InventoryNotice("1 x Wood Foundation")
                Player.Message("You are not allowed to place more than [ " + str(DataStore.Get("BuildingRestriction", "Max Foundations")) + " ] foundations")
                break
 

Jakkee

Plugin Developer
Plugin Developer
Contributor
Jul 28, 2014
1,465
927
113
Australia
If It happens with Try, then It is not the destroy function.

I removed some unnecessary coding stuffs, and changed the structure of the code to help you understand what's continue.

Give it a try.
Python:
def On_EntityDeployed(self, Player, Entity):
    if Entity.Name == "WoodPillar":
        #Entity locations are in float, this is just a case stuff.
        height = round(float(DataStore.Get("BuildingRestriction", "Max Height")), 0)
        for foundation in Entity.GetLinkedStructs():
            if foundation.Name != "WoodFoundation":
                continue
            if height < Entity.Y - foundation.Y:
                try:
                    Entity.Destroy()
                except:
                    Server.Broadcast("Failed to destroy the entity.")
                Player.Inventory.AddItem("Wood Pillar")
                Player.InventoryNotice("1 x Wood Pillar")
                Player.Message("You are not allowed to build more than [ " + str(round(DataStore.Get("BuildingRestriction", "Max Height"), 0) / 4) + " ] pillars high")
                break
    elif Entity.Name == "WoodFoundation":
        count = 0
        max = int(DataStore.Get("BuildingRestriction", "Max Foundations"))
        for foundation in Entity.GetLinkedStructs():
            if foundation.Name != "WoodFoundation":
                continue
            count += 1
            if count == max:
                try:
                    Entity.Destroy()
                except:
                    Server.Broadcast("Failed to destroy the entity.")
                Player.Inventory.AddItem("Wood Foundation")
                Player.InventoryNotice("1 x Wood Foundation")
                Player.Message("You are not allowed to place more than [ " + str(DataStore.Get("BuildingRestriction", "Max Foundations")) + " ] foundations")
                break
Still gets the same error, at the moment its just annoying :p
 

mikec

Master Of All That I Survey
Administrator
Jul 12, 2014
296
152
28
Los Angeles, California, USA
I get NullReferenceException: Object reference not set to an instance of an object when I do Entity.Destroy()
Would post logs but its not showing up in the logs
If you see it on the console, the rest of it is in the rust server log in rust_server_Data, not the Fougerite logs in the plugin area.
 

Jakkee

Plugin Developer
Plugin Developer
Contributor
Jul 28, 2014
1,465
927
113
Australia
If you see it on the console, the rest of it is in the rust server log in rust_server_Data, not the Fougerite logs in the plugin area.
Output.log
Code:
NullReferenceException: Object reference not set to an instance of an object
  at Facepunch.MeshBatch.Runtime.MeshBatchPhysicalOutput.ActivateImmediatelyUnchecked () [0x00000] in <filename unknown>:0

  at Facepunch.MeshBatch.Runtime.MeshBatchPhysicalOutput.OnQueue () [0x00000] in <filename unknown>:0

  at Facepunch.MeshBatch.Runtime.Sealed.MeshBatchPhysicalIntegration.IntegrateOne () [0x00000] in <filename unknown>:0

  at Facepunch.MeshBatch.Runtime.Sealed.MeshBatchPhysicalIntegration.FixedUpdate () [0x00000] in <filename unknown>:0