britzl / defold-orthographic

Orthographic camera functionality for the Defold game engine
MIT License
164 stars 18 forks source link

When switching between two collections containing Orthographic, the console returns errors. #28

Closed vgreen7 closed 5 years ago

vgreen7 commented 5 years ago

When working with Orthographic I have realized that when switching between collections that both have Orthographic in them returns an error:

_

Error:Script: /orthographic/camera.lua:410: attempt to index a nil value stack traceback: /orthographic/camera.lua:410: in function 'send_view_projection' /orthographic/camera.script:63: in function </orthographic/camera.script:60>

_

image

britzl commented 5 years ago

I added an example with two scenes and two cameras:

https://github.com/britzl/defold-orthographic/tree/master/example/multicamera

Each scene is a collection loaded via a proxy. Each scene contains a camera game object following a player game object. This example works without any problems.

Can you please create a minimal example reproducing the problem you have?

vgreen7 commented 5 years ago

Thank you so much for for your time and help. Here is my repo with the issue in it: https://github.com/vgreen7/camera-test

Thanks so much again for you help

britzl commented 5 years ago

The project didn't compile (broken atlases and a typo in one of the script files). I was able to reproduce your problem when I fixed those issues. The reason your project fails is the following:

You unload level1 and load level2 at the same time. When level2 is loaded the camera in level 2 registers with Orthographic. When level1 is unloaded the camera in level 1 is unregistered from Orthographic.

The problem in your case is that both cameras have the same id and level1 finishes unloading after level2 has loaded which causes the camera to get unregistered.

Either give each camera a unique id or make sure that level1 gets completely unloaded before loading level2.

vgreen7 commented 5 years ago

Wow, I can't believe the answer was so simple, thanks so much!!