{"action":"created","issue":{"url":"https://api.github.com/repos/robotology/wysiwyd/issues/28","labels_url":"https://api.github.com/repos/robotology/wysiwyd/issues/28/labels{/name}","comments_url":"https://api.github.com/repos/robotology/wysiwyd/issues/28/comments","events_url":"https://api.github.com/repos/robotology/wysiwyd/issues/28/events","html_url":"https://github.com/robotology/wysiwyd/issues/28","id":114251218,"number":28,"title":"[OPCClient] Invalid pointers","user":{"login":"Tobias-Fischer","id":5497832,"avatar_url":"https://avatars.githubusercontent.com/u/5497832?v=3","gravatar_id":"","url":"https://api.github.com/users/Tobias-Fischer","html_url":"https://github.com/Tobias-Fischer","followers_url":"https://api.github.com/users/Tobias-Fischer/followers","following_url":"https://api.github.com/users/Tobias-Fischer/following{/other_user}","gists_url":"https://api.github.com/users/Tobias-Fischer/gists{/gist_id}","starred_url":"https://api.github.com/users/Tobias-Fischer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tobias-Fischer/subscriptions","organizations_url":"https://api.github.com/users/Tobias-Fischer/orgs","repos_url":"https://api.github.com/users/Tobias-Fischer/repos","events_url":"https://api.github.com/users/Tobias-Fischer/events{/privacy}","received_events_url":"https://api.github.com/users/Tobias-Fischer/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/robotology/wysiwyd/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/robotology/wysiwyd/milestones/1","html_url":"https://github.com/robotology/wysiwyd/milestones/Second%20year%20review","labels_url":"https://api.github.com/repos/robotology/wysiwyd/milestones/1/labels","id":1447539,"number":1,"title":"Second year review","description":"","creator":{"login":"Tobias-Fischer","id":5497832,"avatar_url":"https://avatars.githubusercontent.com/u/5497832?v=3","gravatar_id":"","url":"https://api.github.com/users/Tobias-Fischer","html_url":"https://github.com/Tobias-Fischer","followers_url":"https://api.github.com/users/Tobias-Fischer/followers","following_url":"https://api.github.com/users/Tobias-Fischer/following{/other_user}","gists_url":"https://api.github.com/users/Tobias-Fischer/gists{/gist_id}","starred_url":"https://api.github.com/users/Tobias-Fischer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tobias-Fischer/subscriptions","organizations_url":"https://api.github.com/users/Tobias-Fischer/orgs","repos_url":"https://api.github.com/users/Tobias-Fischer/repos","events_url":"https://api.github.com/users/Tobias-Fischer/events{/privacy}","received_events_url":"https://api.github.com/users/Tobias-Fischer/received_events","type":"User","site_admin":false},"open_issues":18,"closed_issues":3,"state":"open","created_at":"2015-12-07T12:33:48Z","updated_at":"2015-12-11T17:30:04Z","due_on":"2016-04-18T23:00:00Z","closed_at":null},"comments":6,"created_at":"2015-10-30T11:22:13Z","updated_at":"2015-12-13T19:34:29Z","closed_at":null,"body":"Hi all,\r\nas discussed on slack, we have issues with the `OPCClient`. See for example this code snippet which leads to an invalid pointer, as `checkout()` deletes all the `Entity*`, and allocates new memory for new `Entity*` objects:\r\n```\r\nObject* o = opc->addOrRetrieveEntity<Object>(\"test\");\r\nopc->checkout();\r\ncout<<\"This does not work, because checkout changes the pointers!!!\" << o->name()\r\n```\r\n\r\nMy comments on slack were as follows:\r\nI think we have a fundamental issue. Every time EntitiesCache is used, a list of pointers to entities is returned. However these pointers might change over time (I am not sure why). So if a module uses EntitiesCache, and then iterates over the entities, the actual pointers to the entities might have already changed. And then we see corruptions, as we've seen yesterday in #bcbt-2015. So we need to figure out why the pointer to the entity with the same OPC id changes over time. You might think: Why not always use EntitiesCacheCopy? This is only feasible if a module is only reading attributes from the entities. As soon as an entity needs to be changed, you must use EntitiesCache. Otherwise you change the values of the copy, but not the entity itself.\r\n\r\nIn the meantime, as above, I have found that the `checkout()` is the evil method changing the pointers.\r\n\r\nI guess the following should be discussed:\r\nWhat should `checkout()` do by default? Should `updateCache` be really `true` by default? It deletes all pointers, and retrieves the entities fresh from the OPC. Isn't what we really want an update of the entity, i.e. the entity itself is kept (thus no deleting of any pointers etc.), but the attributes of the entity are updated with the content which is stored in the OPC?\r\n\r\nBest,\r\nTobi"},"comment":{"url":"https://api.github.com/repos/robotology/wysiwyd/issues/comments/164290045","html_url":"https://github.com/robotology/wysiwyd/issues/28#issuecomment-164290045","issue_url":"https://api.github.com/repos/robotology/wysiwyd/issues/28","id":164290045,"user":{"login":"Tobias-Fischer","id":5497832,"avatar_url":"https://avatars.githubusercontent.com/u/5497832?v=3","gravatar_id":"","url":"https://api.github.com/users/Tobias-Fischer","html_url":"https://github.com/Tobias-Fischer","followers_url":"https://api.github.com/users/Tobias-Fischer/followers","following_url":"https://api.github.com/users/Tobias-Fischer/following{/other_user}","gists_url":"https://api.github.com/users/Tobias-Fischer/gists{/gist_id}","starred_url":"https://api.github.com/users/Tobias-Fischer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tobias-Fischer/subscriptions","organizations_url":"https://api.github.com/users/Tobias-Fischer/orgs","repos_url":"https://api.github.com/users/Tobias-Fischer/repos","events_url":"https://api.github.com/users/Tobias-Fischer/events{/privacy}","received_events_url":"https://api.github.com/users/Tobias-Fischer/received_events","type":"User","site_admin":false},"created_at":"2015-12-13T19:34:29Z","updated_at":"2015-12-13T19:34:29Z","body":"Regarding the doubts: I am not too sure what happens in the case to be honest. I think that a `clear()` between the check against `NULL` and the usage of the pointer would corrupt the local object, as `clear()` deletes the (object referenced by the) pointer. Thus, the memory which is referred by the pointer may still contain the object, but might as well be overridden by something completely different as the memory is freed. But I am not too deep into pointers etc. so that view might be wrong. That's why I try to avoid pointers unless I really, really think I need them."}}