{"action":"opened","issue":{"url":"https://api.github.com/repos/Samsung/GearVRf/issues/24","labels_url":"https://api.github.com/repos/Samsung/GearVRf/issues/24/labels{/name}","comments_url":"https://api.github.com/repos/Samsung/GearVRf/issues/24/comments","events_url":"https://api.github.com/repos/Samsung/GearVRf/issues/24/events","html_url":"https://github.com/Samsung/GearVRf/issues/24","id":69198316,"number":24,"title":"GVRF reference counting","user":{"login":"JonShemitz","id":11304782,"avatar_url":"https://avatars.githubusercontent.com/u/11304782?v=3","gravatar_id":"","url":"https://api.github.com/users/JonShemitz","html_url":"https://github.com/JonShemitz","followers_url":"https://api.github.com/users/JonShemitz/followers","following_url":"https://api.github.com/users/JonShemitz/following{/other_user}","gists_url":"https://api.github.com/users/JonShemitz/gists{/gist_id}","starred_url":"https://api.github.com/users/JonShemitz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JonShemitz/subscriptions","organizations_url":"https://api.github.com/users/JonShemitz/orgs","repos_url":"https://api.github.com/users/JonShemitz/repos","events_url":"https://api.github.com/users/JonShemitz/events{/privacy}","received_events_url":"https://api.github.com/users/JonShemitz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-04-17T19:06:50Z","updated_at":"2015-04-17T19:06:50Z","closed_at":null,"body":"GVRF uses a (native code) `std::shared_ptr` based reference counting scheme. It works well enough in 'normal' cases, but does break down in the not-so-special case where you have an object (we see this commonly with scene objects and textures, but it could happen with other objects, too) that goes in and out of the scene graph: When GVRF sees that an object has no native references (just the reference from the Java wrapper) it will 'forget' about the native wrapper and/or `recycle()` the GL resource. This can lead to consequences like eye picking returning a `GVRSceneObject` instead of the subclassed instance (holding app values) that you put into the scene graphs, or even to GVRF crashing when it dereferences `null` in native code.\r\n\r\nWe have what amounts to work-arounds for this: we can manually add references (as _per_ the JavaDoc for `GVRShaders.setMainTexture()`) and we can set the `GVRHybridObject.setKeepWrapper()` flag. Perhaps it would be better to add explicit\r\n\r\n    long GVRHYbridObject.touch(); // addReference()?\r\n    void GVRHYbridObject.release(long); // removeReference()?\r\n\r\nmethods?"}}