# Using Cinder-OpenNI UserApp sample

**URL:** <https://discourse.libcinder.org/t/using-cinder-openni-userapp-sample/990>\
**Category:** CinderBlocks\
**Created:** [December 11, 2017, 11:40pm UTC](https://discourse.libcinder.org/t/using-cinder-openni-userapp-sample/990 "2017-12-11T23:40:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tamarziv](https://avatars.discourse-cdn.com/v4/letter/t/9f8e36/32.png) [@tamarziv](https://discourse.libcinder.org/u/tamarziv)\
**Post date:** [December 11, 2017, 11:40pm UTC](https://discourse.libcinder.org/t/using-cinder-openni-userapp-sample/990/1 "2017-12-11T23:40:28Z")

</div>

I’ve been trying to utilize the openNI2 block discussed here:  
[https://forum.libcinder.org/topic/rfc-cinder-openni](https://forum.libcinder.org/topic/rfc-cinder-openni)

and came across the same issue as christianrakete (last comment on the thread)  
using the UserApp sample.  
Has anyone manage to resolve this issue?

> void release(){  
> if (m\_pFrame != NULL){  
> niteUserTrackerFrameRelease(m\_userTrackerHandle, m\_pFrame); // \<================  
> }  
> m\_pFrame = NULL;  
> m\_userTrackerHandle = NULL;  
> }

> malloc: \*\*\* error for object 0x6080000a1f20: pointer being freed was not allocated  
> \*\*\* set a breakpoint in malloc\_error\_break to debug

---

<div class="post-metadata">

**Author:** ![paul.houx](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/paul.houx/32/31_2.png) [@paul.houx](https://discourse.libcinder.org/u/paul.houx)\
**Post date:** [December 12, 2017, 1:51am UTC](https://discourse.libcinder.org/t/using-cinder-openni-userapp-sample/990/2 "2017-12-12T01:51:49Z")

</div>

`m_pFrame` is not `NULL`, yet points to invalid memory. This could have one of the following causes:

- `m_pFrame` is not initialized to NULL on construction.
- a copy was made of the instance holding `m_pFrame`, but the `m_pFrame` pointer wasn’t copied (check the copy constructor and/or the assignment operator of the class).
- the instance holding `m_pFrame` was itself deleted, but the pointer to it was not reset to `NULL`, so upon calling `release()`, invalid memory was being read.
- the instance holding `m_pFrame` could not be constructed in the first place, due to an out of memory error, but was used nonetheless.

Do a search on `m_pFrame` and see where it is set, read and/or written to. Then place breakpoints at suspicious pieces of code.

---

<div class="post-metadata">

**Author:** ![tamarziv](https://avatars.discourse-cdn.com/v4/letter/t/9f8e36/32.png) [@tamarziv](https://discourse.libcinder.org/u/tamarziv)\
**Post date:** [December 16, 2017, 6:36pm UTC](https://discourse.libcinder.org/t/using-cinder-openni-userapp-sample/990/3 "2017-12-16T18:36:31Z")

</div>

Thank you Paul so much for your quick response, unfortunately only now I had the chance to test your ideas,  
I’ve attempted creating a deep copy of the user frame originating from:

> void UserApp::onUser( nite::UserTrackerFrameRef frame, const OpenNI::DeviceOptions& deviceOptions )

Basically adding:

> if( !frame.isValid() )  
> return;
> 
> nite::UserTrackerFrameRef frameCopy = nite::UserTrackerFrameRef( frame );  
> frame.release();

Hoping this will work, I’m still suspecting  
this is not completely thread safe, but will report my findings.
