Page 1 of 1

sim.saveImage causes the script to freeze/crash

Posted: 04 Mar 2024, 22:46
by fabio53443
Hi! I'm new to CoppeliaSim and i'm trying to build a simulator of a 4wd robot for a school project.
I'm using the ZMQ python API and a simple Lua script that only opens up the API port.
I've run into an issue: whenever i try to sim.saveImage, this gets logged into the Coppelia console and the python program hangs:

Code: Select all

[Connectivity >> ZMQ remote API server@addOnScript:error] [string "Connectivity >> ZMQ remote API server@addOnSc..."]:439: [string "Connectivity >> ZMQ remote API server@addOnSc..."]:393: ...ktop/Coppelia/luarocks/share/lua/5.3/org/conman/cbor.lua:301: attempt to get length of a number value (local 'value')
{'ret' = {{'data' = 1, }}, }
stack traceback:
    [C]: in function 'error'
    [string "Connectivity >> ZMQ remote API server@addOnSc..."]:393: in field 'send'
    [string "Connectivity >> ZMQ remote API server@addOnSc..."]:511: in function 'coroutineMain'
stack traceback:
    [C]: in function 'error'
    [string "Connectivity >> ZMQ remote API server@addOnSc..."]:494: in field 'resumeCoroutine'
    [string "Connectivity >> ZMQ remote API server@addOnSc..."]:439: in field 'handleQueue'
    [string "Connectivity >> ZMQ remote API server@addOnSc..."]:660: in function 'sysCall_actuation'
This is my code:

Code: Select all

def getImage():
    m, sim = setup()
    cam = sim.getObject('./kinect/rgb')
    data, res = sim.getVisionSensorImg(cam)
    a = sim.saveImage(data, res, 0, "a.png", 10)
  
  
The photo does however get saved in the right folder. The issue does occur if the image is saved either with a name (and in the coppelia folder) or with an absolute path. The issue does not occur if the image is saved to ram by omitting a filename in the path argument.

I've tried to add "sim.handleVisionSensor" but it logs into the python console that the sensor is not tagged for explicit handling and that sim.handleVisionSensor is therefore not required.

Could anyone help me? Thank you very much. If you need the scene file or the entire code i'll be happy to hand it over.

This issue appears on both Windows and Ubuntu systems.

Re: sim.saveImage causes the script to freeze/crash

Posted: 05 Mar 2024, 14:09
by coppelia
Hello Fabio,

indeed, this is a bug!

Do following for a workaround: edit file <installFolder>/addOns/ZMQ remote API server.lua by appending following:

Code: Select all

sim.saveImage = wrap(sim.saveImage, function(origFunc)
    return function(img, res, opt, nm, q)
        local ret = origFunc(img, res, opt, nm, q)
        if type(ret) ~= 'string' then
            ret = ''
        end
        return ret
    end
end)
Let me know if that works.
Cheers

Re: sim.saveImage causes the script to freeze/crash

Posted: 05 Mar 2024, 15:19
by fabio53443
Hi! I've tried to apply the patch but it doesn't seem to work. I'm still getting the same error and the script still hangs. I've tried on Windows and I'll try on Ubuntu later today and let you know.

Best
Fabio

Re: sim.saveImage causes the script to freeze/crash

Posted: 05 Mar 2024, 17:16
by coppelia
I tried on Windows here too, using CoppeliaSim V4.6 rev. 18.
Is the error message still the same? Can you make sure that the patched sim.saveImage is actually ran, e.g. by adding a print in there?

Cheers

Re: sim.saveImage causes the script to freeze/crash

Posted: 05 Mar 2024, 23:30
by fabio53443
Hi! On Ubuntu, it works! The image is saved and the process doesn't hang.
Thank you for your help.