TheDuckCow / godot-road-generator

A godot plugin for creating 3D highways and streets.
MIT License
313 stars 16 forks source link

Road segmetns need to be regenerated on changing scene #92

Closed TheDuckCow closed 1 year ago

TheDuckCow commented 1 year ago

Right now if you switch between scenes, the geometry isn't generated/is lost.

bdog2112 commented 1 year ago

On initial examination, it appears that redraw is not the issue. That is merely a symptom of some other problem.

Here is the message displayed in the console when switching scenes:

modules/gdscript/gdscript_functions.cpp:775 - Instance was not valid on sid: 44017-44018 core/variant_call.cpp:1222 - Attempted method call on a deleted object. res://addons/road-generator/road_network.gd:130 - Attempt to call function 'check_rebuild' in base 'previously freed instance' on a null instance.

So, the trick will probably be to figure out why it's trying to rebuild a deleted object.

bdog2112 commented 1 year ago

Hey @TheDuckCow,

Regarding RoadNetworks not redrawing when there are multiple scenes:

When the Scene is changed, the outgoing Scene exits the tree. In the process, the segid_map dictionary becomes stale. It's also worth noting that RoadNetwork._exit_tree() includes some code to cleanup the segid_map. But, it's commented out because, apparently, it caused other issues.

When an inactive Scene is brought back into focus, it tries to rebuild the Segments using stale data and fails. Thus, manifesting as an inability to redraw.

The simplest solution is to add "segid_map.clear()" to the _exit_tree routine. This works great. When the scene becomes active, it rebuilds the segid_map with current data and all is well. Did you comment out the segid_map code in _exit_tree? What are your thoughts on the proposed solution?

TheDuckCow commented 1 year ago

@bdog2112 Thanks for investigating and sharing these details, definitely helps to more clearly understand what is happening. If you want to make a PR for what you see as the fix, I'll do some though testing of it in both some test projects as well as a live runtime game. It's possible the error I was seeing was during a game run and not in the editor, but I don't specifically remember.

TheDuckCow commented 1 year ago

This has been solved since before the alpha release 0.3.1.