Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo


#10 Roto jumps from variable to variable

Bug (1)
Anton Kaplanyan

Dear Phillipe,

First of all, thanks a lot for creating such an amazing and minimalistic library.

The bug I want to report is related to instable allocation of CTwVars using new operator.

I clear all variables in the bar with TwRemoveAllVars() and then add two variables. That happens every frame before draw. I assume this is a common usage scenario for the library. When I change the value of one variable with +/- everything is fine, however, when I change it with a roto, sometimes the focus jumps and I see the changes of the second variable. I compiled your library in debug and checked whether it is the loss of focus or something. Interestingly, I figured out that the actual pointer to CTwVar (m_Var) in m_Roto member of CTwBar does not change, but the actual name of CTwVar inside the pointer changes. That means that the heap allocator is not stable in allocating these two variables and sometimes might exchange the pointers, or even allocate variables in a new chunk of memory - that could potentially corrupt some other data.

The actual allocation happens at line 4122 of TwMgr.cpp. Probably the easiest way would be to overload the new/delete operators for CTwVarAtom and use some stable scratchpad allocator for it; or alternatively these variables can be stored by value in the container (w/o deallocation of the container memory). This could solve the problem in case of stable list of variables from frame to frame (if there are changes in this list, then probably the roto should be reset).

Hope I provided is enough info to reproduce and fix the problem.

Best wishes,
Anton Kaplanyan