pokepetter / ursina

A game engine powered by python and panda3d.
https://pokepetter.github.io/ursina/
MIT License
2.13k stars 321 forks source link

Loading issue for settings.py #662

Closed jmottster closed 2 months ago

jmottster commented 4 months ago

I had a problem where .bam files were not being saved properly. It took me a long time to figure it out. One thing I came across in my debugging is an issue when using settings.py to set (reset) application.asset_folder and application.compressed_models_folder.

In mesh.py, the save() method has a variable named "folder" which defaults to application.compressed_models_folder. When this method is called from mesh_importer.py (line 78), it relies on this default setting of folder. However, the mesh.py file must get loaded before a local settings.py file is, because "folder" has the default value of application.compressed_models_folder rather than any changes to the value set by settings.py.

Make sense? This issue might happen in other places with other application vars, this is just where I ran into it. I suspect that load_settings() is getting called too late in some cases. How local settings are pulled in may have to be reworked and pulled in sooner than they currently are.

pokepetter commented 2 months ago

Yeah, it need to get the value each time those functions runs, since the default values would be the what the value is at time of import.

pokepetter commented 2 months ago

I think the solution is to instead of ...

def load_model(name, folder=application.asset_folder):
    ...

... do this:

def load_model(name, folder=None):
    if folder is None:
        folder = application.asset_folder

Or, if we want to keep the information about the default value in the function declaration :

def load_model(name, folder=Func(getattr, application, 'asset_folder')):
    if callable(folder):
        folder = folder()
pokepetter commented 2 months ago

Fixed.