{"action":"closed","issue":{"url":"https://api.github.com/repos/wxphp/wxphp/issues/17","labels_url":"https://api.github.com/repos/wxphp/wxphp/issues/17/labels{/name}","comments_url":"https://api.github.com/repos/wxphp/wxphp/issues/17/comments","events_url":"https://api.github.com/repos/wxphp/wxphp/issues/17/events","html_url":"https://github.com/wxphp/wxphp/issues/17","id":14726544,"number":17,"title":"Problem with reference counted objects","user":{"login":"tsahlin","id":4242502,"avatar_url":"https://avatars.githubusercontent.com/u/4242502?v=3","gravatar_id":"","url":"https://api.github.com/users/tsahlin","html_url":"https://github.com/tsahlin","followers_url":"https://api.github.com/users/tsahlin/followers","following_url":"https://api.github.com/users/tsahlin/following{/other_user}","gists_url":"https://api.github.com/users/tsahlin/gists{/gist_id}","starred_url":"https://api.github.com/users/tsahlin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tsahlin/subscriptions","organizations_url":"https://api.github.com/users/tsahlin/orgs","repos_url":"https://api.github.com/users/tsahlin/repos","events_url":"https://api.github.com/users/tsahlin/events{/privacy}","received_events_url":"https://api.github.com/users/tsahlin/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2013-05-24T14:32:00Z","updated_at":"2015-11-22T21:50:28Z","closed_at":"2015-11-22T21:50:28Z","body":"There is a problem with functions that return reference counted objects such as wxFont.\r\n\r\nFor example using the method GetFont in wxWindow:\r\n\r\n```php\r\n$font = $this->GetFont();\r\nvar_dump($font->GetFaceName());\r\n```\r\n\r\nThis will often lead to a seg fault because the underlying wxFont has been freed when $font->GetFaceName is called.\r\n\r\nI've tried fixing PHP_METHOD(php_wxWindow, GetFont), and increasing the reference count of the returned value helps the problem:\r\n\r\n```cpp\r\nwxFont value_to_return0;\r\nvalue_to_return0 = ((wxWindow_php*)native_object)->GetFont();\r\n\r\n((wxRefCounter *) value_to_return0.GetRefData())->IncRef();\r\n\r\nvoid* ptr = safe_emalloc(1, sizeof(wxFont_php), 0);\r\nmemcpy(ptr, &value_to_return0, sizeof(wxFont));\r\nobject_init_ex(return_value, php_wxFont_entry);\r\n```\r\n\r\nI haven't yet looked into how to solve it in the code generator. Perhaps you have an idea of how to do it?"}}