Render.draw() expects matrix instead of table for options (SOLVED)

I want to verify if this is a problem only for me?

If I use render.draw according to the documentation the second argument should be a table with options, where I can define e.g. frustum and constants, but when I run my code today, I saw an error:

render.draw(predicates.model, { frustum = camera_world.frustum })

Error:

ERROR:SCRIPT: render/cute.render_script:105: bad argument #5 to 'draw' (matrix4 expected, got table)
stack traceback:
[C]:-1: in function draw
render/cute.render_script:105: in function draw_function
render/helper.lua:165: in function with_material
render/cute.render_script:98: in function draw_function
render/helper.lua:153: in function to_render_target
render/cute.render_script:90: in function <render/cute.render_script:57>

Why it even points out argument #5?

It works (doesn’t show error), when I write:

    render.draw(predicates.model, camera_world.frustum)

Defold: 1.9.1 alpha
Engine: 691478c02875b80e76da65d2f5756394e7a906b1

Argument #5 is camera_world.frustum, which is a table. If this render script you’re using still uses the old naming convention, frustum is the name of the options table, not the frustum matrix. The matrix is normally camera_world.frustum.frustum.

To avoid confusion between the table and matrix, I renamed the options table to opts in my render scripts. :+1:

3 Likes

Thank you, this was precisely my issue, indeed frustum was an options table, that’s why render.draw(predicates.model, camera_world.frustum) works :smiley: And here’s a fix for what I needed (then I can also add constants):

render.draw(predicates.model, { frustum = camera_world.frustum.frustum })

Good tip!

1 Like