Python b0 API - ValueError: NULL pointer access

Report crashes, strange behaviour, or apparent bugs
Post Reply
Ravise
Posts: 2
Joined: 03 Mar 2020, 15:31

Python b0 API - ValueError: NULL pointer access

Post by Ravise »

Hello,

I'm trying to use CoppeliaSim as an environment for my reinforcement learning problem. I've made the scene in CoppeliaSim and I'm connecting to it from python using b0 API. I've made a binding from OpenAI gym to CoppeliaSim and I'm using the gym in stable_baselines. Randomly, I encounter following error:

Code: Select all

Traceback (most recent call last):
  File "runner.py", line 159, in <module>
    main(rest_of_args)
  File "runner.py", line 74, in main
    tb_log_name=arguments.name,
  File "/home/me/.virtualenvs/vrep/lib/python3.6/site-packages/stable_baselines-2.10.0-py3.6.egg/stable_baselines/a2c/a2c.py", line 261, in learn
  File "/home/me/.virtualenvs/vrep/lib/python3.6/site-packages/stable_baselines-2.10.0-py3.6.egg/stable_baselines/common/runners.py", line 48, in run
  File "/home/me/.virtualenvs/vrep/lib/python3.6/site-packages/stable_baselines-2.10.0-py3.6.egg/stable_baselines/a2c/a2c.py", line 360, in _run
  File "/home/me/.virtualenvs/vrep/lib/python3.6/site-packages/stable_baselines-2.10.0-py3.6.egg/stable_baselines/common/vec_env/base_vec_env.py", line 150, in step
  File "/home/me/.virtualenvs/vrep/lib/python3.6/site-packages/stable_baselines-2.10.0-py3.6.egg/stable_baselines/common/vec_env/dummy_vec_env.py", line 46, in step_wait
  File "/home/me/git/diplomka-src/coppelia_gym/gym_snake/envs/gym_generic.py", line 96, in reset
    self._start_simulation()
  File "/home/me/git/diplomka-src/coppelia_gym/gym_snake/envs/gym_generic.py", line 274, in _start_simulation
    "sim.boolparam_threaded_rendering_enabled", True, self.servicecall
  File "/home/me/git/diplomka-src/coppeliasim_api/b0RemoteApi.py", line 392, in simxSetBoolParameter
    return self._handleFunction('SetBoolParameter',reqArgs,topic)
  File "/home/me/git/diplomka-src/coppeliasim_api/b0RemoteApi.py", line 73, in _handleFunction
    rep = msgpack.unpackb(self._serviceClient.call(packedData))
  File "/home/me/git/diplomka-src/coppeliasim_api/b0.py", line 234, in call
    rep_bytes = bytearray(outarr.contents)
ValueError: NULL pointer access
2020-04-25 14:07:31 [`g���] error: HB: Context was terminated
2020-04-25 14:07:41 [`g���] error: HB: Context was terminated
2020-04-25 14:07:51 [`g���] error: HB: Context was terminated
etc. every 10 seconds. The program is terminated, but the python interpret doesn't exit.

Related code segment in b0.py

Code: Select all

class ServiceClient:
    def call(self, data):
        buf = ct.c_char_p(data)
        sz = len(data)
        outsz = ct.c_size_t()
        outbuf = b0_service_client_call(self._cli, buf, sz, ct.byref(outsz))
        outarr = ct.cast(outbuf, ct.POINTER(ct.c_ubyte * outsz.value))
        rep_bytes = bytearray(outarr.contents)
        b0_buffer_delete(outbuf) # new on 16.01.2020
        return rep_bytes
The middle of the stacktrace differs sometimes, but the exception always origins from (I think the line nr. remains the same, but I'm not 110% sure about that)

Code: Select all

File "/home/me/git/diplomka-src/coppeliasim_api/b0.py"
ValueError: NULL pointer access
and happens during

Code: Select all

  File "/home/me/git/diplomka-src/coppelia_gym/gym_snake/envs/gym_generic.py", line 96, in reset
    self._start_simulation()
My environment is:
  • CoppeliaSim Edu V4.0.0. (rev. 4)
  • $ python --version
    Python 3.6.9
  • $ cat /etc/lsb-release
    DISTRIB_ID=Ubuntu
    DISTRIB_RELEASE=18.04
    DISTRIB_CODENAME=bionic
    DISTRIB_DESCRIPTION="Ubuntu 18.04.4 LTS"
I've renamed simAddOnScript-b0RemoteApiServer.lua to simAddOnScript_b0RemoteApiServer.lua to autostart the b0 server, no other changes were done in the simulator dir. I'm inheriting from b0RemoteApi.RemoteApiClient to add some wrapper methods, but since the "wrapper" object does not appear in the stacktrace, I think it's safe to assume the problem is not there.

Client initialization (I increased the timeout per advice in https://forum.coppeliarobotics.com/viewtopic.php?t=7858):

Code: Select all

 self._client = Api(
     nodeName="b0RemoteApi_pythonClient",
     channelName="b0RemoteApiAddOn",
     inactivityToleranceInSec=60,
     timeout=300,
)
My questions are:
  • What is the error caused by?
  • What should I do to avoid it?
Thanks in advance for any help on this issue. I'll provide more information if needed.

coppelia
Site Admin
Posts: 10336
Joined: 14 Dec 2012, 00:25

Re: Python b0 API - ValueError: NULL pointer access

Post by coppelia »

Hello,

does the error always happen with the same call (i.e. simxSetBoolParameter), or does it also happen with other functio calls? Do you call that function as a service call? If yes, does it make a difference if you call that function with the default publisher?

Cheers

Ravise
Posts: 2
Joined: 03 Mar 2020, 15:31

Re: Python b0 API - ValueError: NULL pointer access

Post by Ravise »

Hi,
the ValueError is raised from different function calls in the middle of the traceback. It is always a simxServiceCall(). I'll try with publishers and report back if the issue persists.

Post Reply