xyz

Here is the function used to manually create 20 instances of the object:

func shoot():
	var projectiles_node : Node = $"../Projectiles"
	
	for i in range(0, 20):
		var proj_inst = _projectile_scene.instantiate()
		
		var gtran : Transform3D = $Head/SpringCamera.global_transform
		
		var direction = gtran.basis.z
		
		var camera_pos : Vector3 = $Head/SpringCamera.global_transform.origin
		var test_pos : Vector3  = camera_pos + direction * -3
		
		proj_inst.transform.origin = camera_pos + direction * -3
		
		
		var velocity : Vector3 = Vector3.ZERO
		
		velocity = direction * -20.0
		
		proj_inst.transform.basis = gtran.basis
		
		proj_inst.set_velocity(velocity)
		
		var rpg : RPG7 = proj_inst.get_node("RPG7") as RPG7
		
		rpg.set_creator(self)
		
		projectiles_node.add_child(proj_inst)

Edit: Tried call_defered but it still crashes with same error.

  • xyz replied to this.

    And I also have 6 npc aircrafts shooting at 20ms interval at my character, they spam like 300ish objects per second, and throw them at my character, the objects also get deleted after 4 seconds, but those objects don't seem to have the crash problem as the one shot by my character manually, The only different betwee my player's projectile and npc projectile is the shape of the CollisionShape3D, so I think the the BoxShape3D I am using for the problematic player-shot projectile object is the culprit of the crash. But that is just my guess though.

    Edit: Changed from BoxShape3D to SphereShape3D as CollisionShape3D, and it still crashes after spamming like 300 objects =/

    xyz I uploaded the whole project, it's just a side project/sandbox to test some stuff for my other game, I will make this game open-source soon anyway. -.-

    godetteofvictoryrev0.zip
    22MB

    Steps to reproduce:

    1. Spam clicking left-mouse-button at any location or facing, it should crash after 8 seconds or so (after the first free of the rocket timeout)
    • xyz replied to this.

      MagickPanda That's not a minimal project that reproduces the problem. Making it can often help to figure it out yourself. So put in some effort and make a minimal project instead of just uploading the whole project in the state you got stuck in.

      Wild guess: Try setting the CollisionShape3D's disabled property to true before calling queue_free().

      • I was really interested to know what the problem is so I tried to recreate what you did using only what you showed us here, and with some naming and scene tree related modifications, your code actually works flawlessly except for one thing.
      • The console shouted at me with an Invalid call nonexistent function 'set_creator' I had to comment it out.
      • At first I thought it was a built-in method of some class, haha silly me.
      • So what does this function do? I suspect your problem lies in this function or the RPG7 class.
      • As you said, you face the problem when the player shoots the objects and not when the aircrafts do.
      • If you make the aircrafts shoot RPG7 projectiles, and use the same shoot function showed here (except that the transforms are from the aircraft and not the camera), do you get thrown an error?
      • If you make the player shoot whatever the aircrafts are shooting, and/or use their shoot() function, does it work with no problems.

      set_creator is method to assign and store rpg's parent as attacker, to do some player buff/weapon info query later, like damage, speed etc, but it has no function atm.

      I think the crash is related to 2 or more Area 3Ds got freed when they overlapped at the same location, that's why I created 20 Area3D node with one click. But for some reason it's not 100% triggering the crash if you don't spam enough rocket projectiles.
      I tested on a few PC ranging from windows and ubuntu or ubuntu_like OS, they seem to all have the crashing problem, and on some platform it just freezes the entire OS. -.-

      I will give Dave's method a try, hopefully it will rectify the crash.

      godetteofvictoryrev1.zip
      22MB

      Tried disabling physics with set_physics_process/internal, but it still crashes upon first deletion of rocket object.
      So pls lemme know if I did something wrong with using/deleting area3D or disabling it -.-

      Thanks.

      [unknown] Your project is a bit messy. You're not actually instantiating rpg_7.tscn as you described earlier but some scene that's embedded in player2.tscn and has a StaticBody3D as a root node and rgp_7.tscn as its child. This may or may not contribute to the problem.

      Anyway, never instantiate new physics objects including areas from _physics_process(). So don't call shoot() from there, call it from _input() instead.

      Also don't mix _input() event handler and Input object queries for handling input. It's confusing and non-elegant. Use one or the other.

      [unknown]

      I think I have already replaced rpg_7's root node 'projectile.tscn' from StaticBody3D to Node3D to avoid potential conflicts, I will double-check if its type is changed 'Node3D'.

      The rpg_7 is a child node of projectile.tscn, I have projectile as packed scene in player2.tscn, and instantiate projectile.tscn in 'shoot' function:

      @export var _projectile_scene : PackedScene

      func shoot():
      	var projectiles_node : Node = $"../Projectiles"
      	
      	for i in range(0, 20):
      		var proj_inst = _projectile_scene.instantiate()
              blahblah...

      So I assume projectile's child nodes got instantiated too when projectile packedscene node got instantiated, though I am not 100% sure about godot's hierarchiral instantiating behaviors.

      Your project is a bit messy. You're not actually instantiating rpg_7.tscn as you described earlier but some scene that's embedded in player2.tscn and has a StaticBody3D as a root node and rgp_7.tscn as its child. This may or may not contribute to the problem.

      Thanks for the insight. I will move them to input function, and stick to one input event to handle all input events.

      Anyway, never instantiate new physics objects including areas from _physics_process(). So don't call shoot() from there, call it from _input() instead.

      Also don't mix _input() event handler and Input object queries for handling input. It's confusing and non-elegant. Use one or the other.

      P.S:Moving the input and shoot functions from 'physics_process' to 'process' seemed to fix the problem. Any testing is appreciated.

      • xyz replied to this.

        MagickPanda Moving the input and shoot functions from 'physics_process' to 'process' seemed to fix the problem. Any testing is appreciated.

        I already tested it. Adding collision nodes from _physics_process() is the culprit. The rest I just mentioned in passing.

        [unknown] Wow, good to know!
        Is it a bug or is there some known reason?

        • xyz replied to this.

          BroTa Hard to tell. But introducing new colliders in the middle of the physics frame processing is bound to produce at least some strange behavior. I wasn't exactly excepting crashes though.

          Thanks again for the helps guys.
          Just curious is there somewhere in the doc mentioning what you should NOT do in the process, physics_process?
          I think people will more likely to avoid falling into the pitfall like the one I just crawled out, and it's nign impossible to find the mistake I made without your helps -.-