Question regarding object culling problem...

Hi Caleb,

just noticed we should start a new thread, so I will do this posting my question from the very long dusk thread here :slight_smile:

I’m playing around with Dusk right now and encountered a strange error:

I’m using physics and when the screen is touched applyForce to an object to move it on the x axis. The camera is moving with the object when it is moved. When applyForce is used and the object is moved the following error is stopping the movement after about 1 second:

Attempt to compare nil with number

File: Dusk/dusk_core/misc/functions.lua
Line: 49

stack traceback:
    Dusk/dusk_core/misc/functions.lua:49: in function ‘clamp’
    Dusk/dusk_core/run/camera.lua:212: in function ‘processCameraViewpoint’
    Dusk/dusk_core/run/update.lua:112: in function <Dusk/dusk_core/run/update.lua:111>
    ?: in function <?:205>

Any idea what I have to look at to fix this?

Somehow it seems like the map.setCameraFocus is causing the problem. When turned off everything works fine BUT when turned on it looks like the error appears exactly where the object normally would leave the screen (when the cam movement is turned off). Can it be a object culling problem?

UPDATE:

 

I still can’t figure out the problem (see last post). It looks like a culling problem with the object. The camera is holding the object in the center of the screen, but the error appears when the map (background) is moved the distance from the centered object to the screen borders. It seems like the object is “culled” even when the camera is following the object and keep it centered. Could this be it?

Can you please help me solve this?

Thanks!

Daniela

Is, by any chance, the object you’re tracking an object from an object layer? If so, that’s definitely your problem. You can disable culling for object layers with the preference ‘enableObjectCulling’. Set it before loading your map:

dusk.setPreference("enableObjectCulling", false)
  • Caleb

Hi Caleb,

thank you for your answer. The object is from an object layer.

When using your code I now get the following error when testing:

Runtime error .../camera.lua:258: Invalid focus object passed to `map.setCameraFocus()` stack traceback: &nbsp;&nbsp; &nbsp;[C]: in function 'error' &nbsp;&nbsp; &nbsp;.../camera.lua:258: in function 'setCameraFocus' &nbsp;&nbsp; &nbsp;.../main.lua:169: in main chunk

with line 169 in main.lua using “map.setCameraFocus(object)” for the object from the object layer. The object I got via “object = map.layer[1].object[“TheObject”]”

UPDATE:

I just used a new object NOT from the object layer. I put it into the same map layer and this one is working.

But it would be nice to use objects from the object layer, so edition in Tiled can be done.

I have no idea what is causing the error from above. Can you please help with this Caleb?

  • Dani
     

Hm… Looks like you’ve found a really, truly bug. For now just keep using the non-object-layer object. I’ll try to fix this soon.

The error is occurring because it appears when object culling is off no objects are drawn. Thus, when you call ‘setCameraFocus’, you’re passing nil to it, resulting in the invalid focus object error.

[EDIT]: Fixed. Try the latest master branch.

  • Caleb

Wow! Thank you! :slight_smile:

Is, by any chance, the object you’re tracking an object from an object layer? If so, that’s definitely your problem. You can disable culling for object layers with the preference ‘enableObjectCulling’. Set it before loading your map:

dusk.setPreference("enableObjectCulling", false)
  • Caleb

Hi Caleb,

thank you for your answer. The object is from an object layer.

When using your code I now get the following error when testing:

Runtime error .../camera.lua:258: Invalid focus object passed to `map.setCameraFocus()` stack traceback: &nbsp;&nbsp; &nbsp;[C]: in function 'error' &nbsp;&nbsp; &nbsp;.../camera.lua:258: in function 'setCameraFocus' &nbsp;&nbsp; &nbsp;.../main.lua:169: in main chunk

with line 169 in main.lua using “map.setCameraFocus(object)” for the object from the object layer. The object I got via “object = map.layer[1].object[“TheObject”]”

UPDATE:

I just used a new object NOT from the object layer. I put it into the same map layer and this one is working.

But it would be nice to use objects from the object layer, so edition in Tiled can be done.

I have no idea what is causing the error from above. Can you please help with this Caleb?

  • Dani
     

Hm… Looks like you’ve found a really, truly bug. For now just keep using the non-object-layer object. I’ll try to fix this soon.

The error is occurring because it appears when object culling is off no objects are drawn. Thus, when you call ‘setCameraFocus’, you’re passing nil to it, resulting in the invalid focus object error.

[EDIT]: Fixed. Try the latest master branch.

  • Caleb

Wow! Thank you! :slight_smile: