DescriptionToolDa, ToogleBaseSelect can't deselect



  • On 11/06/2017 at 06:14, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:    
    Platform:      
    Language(s) :     C++  ;

    ---------
    I get a pretty weird behavior in my code. Toogle work for selecting but don't for deselecting.

    I run my code in a drag event from a MouseInput function of a DescriptionToolData class.

    // if we are in point snap mode
                    if (snapResul.snapmode == SNAPMODE_POINT){
      
                        // if the target object is selected
                        if (objSelectedList->Find(snapResul.target) != NOTOK)
                        {
                            BaseContainer* kb_state = NewObjClear(BaseContainer);
                            if (!win->BfGetInputEvent(BFM_INPUT_KEYBOARD, kb_state))
                                _shift = false;
      
                            if (kb_state->GetInt32(BFM_INPUT_QUALIFIER) & QSHIFT)
                                _shift = true;
                            else
                                _shift = false;
      
                            PointObject* pobj = ToPoint(snapResul.target);
                            BaseSelect* bs = pobj->GetPointS();
      
                            if (_shift)
                            {
                                bs->Toggle(snapResul.component);
                            }
                            else
                            {
                                bs->DeselectAll();
                                bs->Select(snapResul.component);
                            }
      
                            DrawViews(DRAWFLAGS_ONLY_ACTIVE_VIEW | DRAWFLAGS_NO_THREAD | DRAWFLAGS_NO_ANIMATION);
                        }
                    }
    

    You can see the full code (and the full project here) => https://github.com/gr4ph0s/AxisConstraint/blob/master/source/tool/graph_constraint_snap.cpp

    I also tested to replace Togle to Deselect. It don't work while if I remplace with Select it work perfectly.



  • On 12/06/2017 at 06:40, xxxxxxxx wrote:

    Hi,

    I tried to reproduce your issue here, using Select(), Deselect() and Toggle() in a DescriptionToolData plugin in MouseInput(), seem to work fine for me, doing exactly what I expected. So there must be something else in your code.

    One more thing, completely unrelated: You have a memory leak in your code, as you are allocating but never free'ing the kb_state BaseContainer. You may want to use AutoAlloc there as well or just simply have the BaseContainer on stack.



  • On 12/06/2017 at 06:52, xxxxxxxx wrote:

    Thanks for taking time to test. Gonna see what can I do and will back to you with more informations !

    And thansk for the tips ! What the main difference beetwen AutoAlloc and AutoNew?
    EDit:I Guess this thread explain it pretty well ! :p 
    https://stackoverflow.com/questions/11256228/what-is-the-difference-between-class-new-and-class-alloc-init-in-ios



  • On 13/06/2017 at 02:37, xxxxxxxx wrote:

    Hi,

    no, the link does not provide a good explanation, as this is more a C4D related thing here.
    I suggest to take a look a the Entity Creation manual.
    Basically the AutoNew is behaving like a smart pointer on classes that can be instantiated via NewObj() (or in C++ standard new()), just calling the constructor of the class after allocation. Where AutoAlloc is thought for the more complex classes in Cinema 4D, where the initialization is done in Alloc() instead of the constructor.



  • On 13/06/2017 at 04:38, xxxxxxxx wrote:

    I fel stupid...
    The problem was prety obvious since I passed SNAPFLAG_IGNORE_SELECTED in my Snap function so that why it's failed.

    Anyway thanks you a lot now I understand way more better how to handle my memory !
    It would be nice to have all the manual listed in the index of the sdk. Even if a quick search with manual give it to you, I'm a lazy guy :p

    But in all case thanks for your daily incredible work !



  • On 13/06/2017 at 05:15, xxxxxxxx wrote:

    Hi,

    please don't feel stupid. I guess, almost everybody here in these forums has this kind of moments.

    Thanks for the suggestion to improve the docs.
    I will just need a bit more info. We know, our current search is not the nicest, especially as it can't do a full-text search on overviews and manuals. But at least the headings of the manuals are searched already. Now, which index would you want the manuals to be listed in? I mean, they are in the sidebar on the left under "Overviews", but I guess you know that already. Or is it about an alphabetical list without any grouping?



  • On 13/06/2017 at 05:41, xxxxxxxx wrote:

    Hehe fel stupid x2 I always tried to find manual and failed in General Information.

    I only readed plugin development in overview (and to be honest I never clicked on overview so I didnt saw the index of overview which is way more explicit about manual are hidden here :p)

    So I guess I get some good lecture for a week or two :D


Log in to reply