Question oapi.get_levelref Not Recognizing Particle Stream Handle?

Thunder Chicken

Resident Lua Script Rabble-Rouser
Donator
Joined
Mar 22, 2008
Messages
5,845
Reaction score
5,509
Points
188
Location
Massachusetts
I created particle streams to mimic the wake and bow wave from my boat. They were working, and I could vary the intensity, but for some reason the code is now throwing errors.

I establish the particle streams and establish their intensities with this code, called within clbk_setclasscaps:

Code:
function make_pretty.particle_streams()

    wake_particle_spec =
    {
        flags = 0,
        srcsize = 0.5,
        srcrate = 10,
        v0 = 0,
        srcspread = 0.25,
        lifetime = 2.0,
        growthrate = 0,
        atmslowdown = 2.0,
        ltype = PARTICLE.DIFFUSE,
        levelmap = PARTICLE.LVL_PSQRT,
        lmin = 0,
        lmax = 2,
        atmsmap = PARTICLE.ATM_PLOG,
        amin = 1e-4,
        amax = 1,
        tex = 0
    }

    bow_wave_particle_spec =
    {
        flags = 0,
        srcsize = 0.5,
        srcrate = 20,
        v0 = 1,
        srcspread = 0.1,
        lifetime = 1.0,
        growthrate = 0,
        atmslowdown = 0.0,
        ltype = PARTICLE.DIFFUSE,
        levelmap = PARTICLE.LVL_PSQRT,
        lmin = 0,
        lmax = 2,
        atmsmap = PARTICLE.ATM_PLOG,
        amin = 1e-4,
        amax = 1,
        tex = 0
    }

    wake_level = 1
    bow_level = 1

    wake = {}

    wake[1] = vi:add_particlestream(wake_particle_spec, vec.add(rudder_pivot, {x=0, y=0, z=-0.5}), {x=0, y=0, z=-1}, wake_level)
    wake[2] = vi:add_particlestream(wake_particle_spec, vec.add(rudder_pivot, {x=-0.35, y=0, z=-0.5}), {x=0, y=0, z=-1}, wake_level)
    wake[3] = vi:add_particlestream(wake_particle_spec, vec.add(rudder_pivot, {x=-0.7, y=0, z=-0.5}), {x=0, y=0, z=-1}, wake_level)
    wake[4] = vi:add_particlestream(wake_particle_spec, vec.add(rudder_pivot, {x=0.35, y=0, z=-0.5}), {x=0, y=0, z=-1}, wake_level)
    wake[5] = vi:add_particlestream(wake_particle_spec, vec.add(rudder_pivot, {x=0.7, y=0, z=-0.5}), {x=0, y=0, z=-1}, wake_level)

    bow_wave = {}

    bow_wave[1] = vi:add_particlestream(bow_wave_particle_spec, vec.add(rudder_pivot, {x=0, y=0, z=5.2}), {x=10, y=0, z=0}, bow_level)
    bow_wave[2] = vi:add_particlestream(bow_wave_particle_spec, vec.add(rudder_pivot, {x=0, y=0, z=5.2}), {x=-10, y=0, z=0}, bow_level)

    wake_intensity = {}

    for i = 1, #wake do

        if wake ~= nil then

            wake_intensity[i] = oapi.particle_getlevelref(wake[i])

        end

    end

    bow_wave_intensity = {}

    for i = 1, #bow_wave do

        if bow_wave[i] ~= nil then

            bow_wave_intensity[i] = oapi.particle_getlevelref(bow_wave[i])

        end

    end

end

Both instances of oapi.particle_getlevelref cause errors (from Orbiter.log): oapi_particle_getlevelref: Argument 1: invalid object. I am again stumped, as I define the particle streams before these calls in the same block! I get no other errors in Orbiter.log set to verbose.
 
I created particle streams to mimic the wake and bow wave from my boat. They were working, and I could vary the intensity, but for some reason the code is now throwing errors.

I establish the particle streams and establish their intensities with this code, called within clbk_setclasscaps:

Code:
function make_pretty.particle_streams()

    wake_particle_spec =
    {
        flags = 0,
        srcsize = 0.5,
        srcrate = 10,
        v0 = 0,
        srcspread = 0.25,
        lifetime = 2.0,
        growthrate = 0,
        atmslowdown = 2.0,
        ltype = PARTICLE.DIFFUSE,
        levelmap = PARTICLE.LVL_PSQRT,
        lmin = 0,
        lmax = 2,
        atmsmap = PARTICLE.ATM_PLOG,
        amin = 1e-4,
        amax = 1,
        tex = 0
    }

    bow_wave_particle_spec =
    {
        flags = 0,
        srcsize = 0.5,
        srcrate = 20,
        v0 = 1,
        srcspread = 0.1,
        lifetime = 1.0,
        growthrate = 0,
        atmslowdown = 0.0,
        ltype = PARTICLE.DIFFUSE,
        levelmap = PARTICLE.LVL_PSQRT,
        lmin = 0,
        lmax = 2,
        atmsmap = PARTICLE.ATM_PLOG,
        amin = 1e-4,
        amax = 1,
        tex = 0
    }

    wake_level = 1
    bow_level = 1

    wake = {}

    wake[1] = vi:add_particlestream(wake_particle_spec, vec.add(rudder_pivot, {x=0, y=0, z=-0.5}), {x=0, y=0, z=-1}, wake_level)
    wake[2] = vi:add_particlestream(wake_particle_spec, vec.add(rudder_pivot, {x=-0.35, y=0, z=-0.5}), {x=0, y=0, z=-1}, wake_level)
    wake[3] = vi:add_particlestream(wake_particle_spec, vec.add(rudder_pivot, {x=-0.7, y=0, z=-0.5}), {x=0, y=0, z=-1}, wake_level)
    wake[4] = vi:add_particlestream(wake_particle_spec, vec.add(rudder_pivot, {x=0.35, y=0, z=-0.5}), {x=0, y=0, z=-1}, wake_level)
    wake[5] = vi:add_particlestream(wake_particle_spec, vec.add(rudder_pivot, {x=0.7, y=0, z=-0.5}), {x=0, y=0, z=-1}, wake_level)

    bow_wave = {}

    bow_wave[1] = vi:add_particlestream(bow_wave_particle_spec, vec.add(rudder_pivot, {x=0, y=0, z=5.2}), {x=10, y=0, z=0}, bow_level)
    bow_wave[2] = vi:add_particlestream(bow_wave_particle_spec, vec.add(rudder_pivot, {x=0, y=0, z=5.2}), {x=-10, y=0, z=0}, bow_level)

    wake_intensity = {}

    for i = 1, #wake do

        if wake ~= nil then

            wake_intensity[i] = oapi.particle_getlevelref(wake[i])

        end

    end

    bow_wave_intensity = {}

    for i = 1, #bow_wave do

        if bow_wave[i] ~= nil then

            bow_wave_intensity[i] = oapi.particle_getlevelref(bow_wave[i])

        end

    end

end

Both instances of oapi.particle_getlevelref cause errors (from Orbiter.log): oapi_particle_getlevelref: Argument 1: invalid object. I am again stumped, as I define the particle streams before these calls in the same block! I get no other errors in Orbiter.log set to verbose.
It can do that if vi:add_particlestream fails.
Is the oapi_particle_getlevelref error the first one in the logs?
Just in case: vi:add_particlestream can fail if you're using the inline GC (or console mode?) of if you disabled particle streams in the visual settings.
Edit: vi:add_particlestream actually returns 2 values, the stream handle and the levelref (not sure if it's working properly) so you can get them both in one go, no need for 2 for loops.
 
Last edited:
It can do that if vi:add_particlestream fails.
Is the oapi_particle_getlevelref error the first one in the logs?
It's the only error.
Just in case: vi:add_particlestream can fail if you're using the inline GC (or console mode?) of if you disabled particle streams in the visual settings.
Oh, for crying out loud 😡...that was the problem. Particle streams were not enabled. Particles work fine again.

How can I check if particle streams are enabled so I can protect against this?
Edit: vi:add_particlestream actually returns 2 values, the stream handle and the levelref (not sure if it's working properly) so you can get them both in one go, no need for 2 for loops.
My code works again, but if I can consolidate code I'd like to try.

Would this be the correct usage?:

particle_handle, level_ref = vi:add_particlestream(...)
 
Last edited:
How can I check if particle streams are enabled so I can protect against this?
I don't think you can directly (even in C++). I'll see if I can make the vi:add_particlestream call return nil instead of a bogus userdata so that you can at least see that the call failed.

Would this be the correct usage?:


particle_handle, level_ref = vi:add_particlestream(...)
Yes that should be it.
 
Back
Top