KinsonDigital / Velaptor

2D game development framework
https://docs.velaptor.io
MIT License
70 stars 16 forks source link

🚧Fix unload content issue #959

Closed CalvinWilkinson closed 3 months ago

CalvinWilkinson commented 3 months ago

Complete The Item Below

Description

Fix an issue where the unload content process is being invoked twice.

This is an issue because this leads to unloaded content from the first invocation being unloaded a second time in the second iteration. This causes null reference exceptions due to attempting to unload already unloaded content.

This issue resides between the Window and GLWindow classes. They both have the ISceneManager being injected which is a singleton. Both classes are invoking the UnloadContent() method which is causing the issue.

Do the following:

  1. Remove the UnloadContent() invocation from the GLWindow class.

    private void GLWindow_Closing()
    {
        this.isShuttingDown = true;
    
    -    SceneManager.UnloadContent();
        Uninitialize?.Invoke();
        . . .
    }
  2. Update the constructors of the Window class to not inject the scene manager anymore.

    • Do this

      protected Window()
      {
          this.nativeWindow = WindowFactory.CreateWindow();
      -    SceneManager = IoC.Container.GetInstance<ISceneManager>();
          this.batcher = IoC.Container.GetInstance<IBatcher>();
      
          Init();
      }
    • And this

      - private protected Window(IWindow window, ISceneManager sceneManager, IBatcher batcher)
      + private protected Window(IWindow window, IBatcher batcher)
      {
          ArgumentNullException.ThrowIfNull(window);
          ArgumentNullException.ThrowIfNull(sceneManager);
          ArgumentNullException.ThrowIfNull(batcher);
      
          this.nativeWindow = window;
      -    SceneManager = sceneManager;
          this.batcher = batcher;
          Init();
      }
  3. Also, update the SceneManager property to use the instance from GLWindow.
    - public ISceneManager SceneManager { get; }
    + public ISceneManager SceneManager => this.nativeWindow.SceneManager;

Acceptance Criteria

### The items to complete to satisfy the Definition of Done.
- [x] All unit tests executed and passed locally after PR work is complete. _(Why? Refer to 'Additional Information' below.)_
- [x] `GLWindow` class updated
- [x] `Window` class updated

ToDo Items

### The items to complete to satisfy the Definition of Done.
- [x] Change type labels added to this issue.  Refer to the _**Change Type Labels**_ section below.
- [x] Priority label added to this issue.  Refer to the _**Priority Type Labels**_ section below.
- [x] Issue linked to the correct milestone _(if applicable)_.

Issue Dependencies

No response

Related Work

No response

Additional Information:

Unit Tests

Reasons for local unit test execution:

  • Unit tests might pass locally but not in the CI environment during the status check process or vice-versa.
  • Tests might pass on the developer's machine but not necessarily on the code reviewer's machine.
  • If you notice that the test status check has passed but the test failed locally, please notify a project maintainer!

💡Warning💡 If the unit tests pass remotely and are not executed locally, this means we could be letting a bug slip into production. Though bugs will always exist in some capacity, we should all do our part to help prevent them from happening.

Change Type Labels

Change Type Label
Bug Fixes 🐛bug
Breaking Changes 🧨breaking changes
New Feature ✨new feature
CICD Changes ♻️cicd
Config Changes ⚙️config
Performance Improvements 🏎️performance
Code Doc Changes 🗒️documentation/code
Product Doc Changes 📝documentation/product

Priority Type Labels

Priority Type Label
Low Priority low priority
Medium Priority medium priority
High Priority high priority

Code of Conduct