Influence-Engine / Influence

Influence Engine - 2D and 3D game engine
MIT License
2 stars 1 forks source link

Handle Null Main Camera in Render Method #3

Closed leAdmin666 closed 4 months ago

leAdmin666 commented 4 months ago

Currently, the engine crashes if there is no main camera when the Render method is called. To improve the robustness of the engine and ensure it does not crash in such scenarios, we need to implement better error handling. This would not only prevent crashes but also enhance the overall stability of the engine.

image

Steps to Reproduce:

  1. Create a GameObject and add the component that contains the Render method.
  2. Ensure there is no main camera set in the scene.

Expected Behavior:

The engine should not crash. Instead, it should gracefully handle the absence of a main camera, possibly logging an error message or using a default fallback behavior.

Actual Behavior:

The engine crashes due to a null reference when trying to access Camera.mainCamera.

realQuartzi commented 4 months ago

Good catch!

For this case the ideal way to handle it would be all together to not allow the rendering to occur. Since if there is no camera then we should not render objects that are in world space.

Additionally on top of that the camera itself is currently in a provoking state as it is not setting itself as mainCamera on creation, regardless of the constructor having it set.

Will look into this further soon!

realQuartzi commented 4 months ago

Fixed in d2eb492cdca6db44a262e543552bb8031ace0765. <3