Sometimes weird values from API call

Report crashes, strange behaviour, or apparent bugs
Post Reply
SeveQ
Posts: 34
Joined: 25 Jul 2013, 20:46

Sometimes weird values from API call

Post by SeveQ »

Hi folks,

sometimes, sporadically but (talking about several ten seconds to minutes), I get weird values from a remote API call. Sometimes it's a NaN, sometimes values that are completely wrong. Is there a known issue regarding reliability of remote API calls? This is also expressing in UI events that fire although I don't do anything with the custom UI. In all of these cases I don't get an error from the API call. It's returning simx_error_noerror as expected.

//edit: I've switched to regular API calls and using signals for data transfer and with that I'm getting the same wrong values. So, it's not remote API related!

Any idea?

Cheers,
Hendrik

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

Re: Sometimes weird values from API call

Post by coppelia »

Hello Hendrik,

that is weird. Actually this can happen if you provide object positions that are faulty, for example (e.g. x/0 or similar). Those are not always checked when the call is made, and can propagate. Can you give us a concrete code example where this happens, also sporadically?

Cheers

SeveQ
Posts: 34
Joined: 25 Jul 2013, 20:46

Re: Sometimes weird values from API call

Post by SeveQ »

Hmm... I've investigated this issue a little further and after all it seems to be related to the remote API in some way.

I've inserted some ifs into my code to check results for NaN or out of range values. But they don't, umh, fire. Despite that I get NaNs and out of range values on the other side of the signal channel (remote API client). I use the remoteApi.dll in a .NET wrapper class via P/Invoke (as mentioned in another thread). Maybe it's related to that somehow.

Another possible cause might be a race condition between setting a signal and accessing the value through the remote API. Or have you already taken measures to prevent this?

I can give you code examples when we've narrowed down the problem further. For now I'd probably have to give you my whole project to reproduce the misbehaviour.

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

Re: Sometimes weird values from API call

Post by coppelia »

Race conditions are normally prevented by mutexes, and should not occure. Other things you should be aware of:
  • when a remote API function returns a data pointer, the data remains valid until another remote API function is called.
  • when a remote API function somehow fails, or reports a failure, then the promised data will not be valid. Make sure to always check for call success or failure.
Cheers

SeveQ
Posts: 34
Joined: 25 Jul 2013, 20:46

Re: Sometimes weird values from API call

Post by SeveQ »

Alright, so it's possible that the race condition (invalidating a pointer by another remote API call before its value can be read) is on my side as I'm using threads to fetch the data from several sources by using the remote API. So, have I got it right that the remote API isn't thread safe?

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

Re: Sometimes weird values from API call

Post by coppelia »

The remote API is capable of multithreaded operation, however, a given client ID should not be accessed from several different threads.

Cheers

SeveQ
Posts: 34
Joined: 25 Jul 2013, 20:46

Re: Sometimes weird values from API call

Post by SeveQ »

Alright then... That might be the cause. I'll have a look into it. Thanks a lot!

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

Re: Sometimes weird values from API call

Post by coppelia »

For reference, this topic includes the resolution.

Post Reply