daz-b-like / ProCam2D_Godot4.x

The ultimate camera for all your 2D needs.
MIT License
47 stars 2 forks source link

Critical Error on previously freed Level Scene when using PCamRoom Nodes in runtime instantiated and freed scenes. #5

Closed HiIAmBarney closed 3 weeks ago

HiIAmBarney commented 3 weeks ago

Describe the bug Freeing a Scene with a PCamRoom Node throws an Error: "Invalid access to property or key 'global_position' on a base object of type 'previously freed'."

To Reproduce Steps to reproduce the behavior:

  1. Create a Level Scene with a PCamRoom Node Setup. (Player and ProCam are not necessarily part of the instantiated Level Scene)
  2. Instantiate the new Level Scene (With a PCamRoom Node Setup) and Change the current Scene to the new Scene
  3. Free the previously instantiated Scene

Expected behavior The newly instantiated Scene should have its PCamRoom Node overwrite the current PCamRoom Node or freeing the previously instantiated PCamRoom Node should safely disconnect on leaving the tree.

Desktop (please complete the following information):

Additional context This is a follow-up issue on the PCamRoom instantiation issue.

daz-b-like commented 3 weeks ago

Hey @HiIAmBarney . I added some safety checks. Here's the new version. It should work fine now.. Thanks again for reporting. If you have any issues let me know. Good day.

HiIAmBarney commented 3 weeks ago

There IS in fact an Issue with this. When I switch rooms now, the camera Zooms in (and stays Zoomed until I leave the PCamRooms influence), even though the Zoom factor is set to 1 within the Node. I added some Screenshots, though, pardon my placeholder Art, it's from a Game Jam I participated in, that got scrapped mid-project, I am working on realizing it.

This is the Room 1 (In-Game) Room1

This is the Room 2 (In-Game) Room2

This is the Room 2 (In_Editor) Room2InEditor

Edit: Don't mind the Debug Velocity and Positional Values, these are not hooked up atm.

daz-b-like commented 3 weeks ago

I'm not really clear with how you intend this to work so pardon me if I'm wrong. I've noticed the height of room 2 is 192px. I made it so that the rooms never show what's outside their boundaries. In this case the room automatically adjusts the PCam zoom level in order to fit its height to the screen to avoid showing what's outside its boundary and its zoom factor becomes relative to the new zoom level. To avoid auto zooming, the rooms width and height need to be equal or more than the viewports width and height. Try setting both rooms the same height maybe?

HiIAmBarney commented 3 weeks ago

That makes A LOT of sense. Thanks, King! Your Asset will be invaluable for my Progress, I'll pray for your good fortune and certainly praise your work within the Credits.

daz-b-like commented 3 weeks ago

Thanks mate! wish you luck.