Polling memory



  • On 06/07/2014 at 17:27, xxxxxxxx wrote:

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

    ---------
    Hi folks,
     
    I have a little bug in my code where if I'm polling something with the mouse, the dialog starts to look 'washed-out' if it goes on for too long (which, is usually no more than a few seconds..!). Sometimes it disappears altogether.
     
    I'm sure I've read this somewhere before, but can't find any link or reference to it as I don't recall what terms were used. How do we navigate this?
     
    Cheers,
     
    WP.



  • On 07/07/2014 at 13:12, xxxxxxxx wrote:

    Originally posted by xxxxxxxx

    <ADDRESS>
    User Information:
    Cinema 4D Version:   R14 
    Platform:   Windows  ;   
    Language(s) :    
    C++  ;

    ---------
    </ADDRESS> Hi folks,

    I have a little bug in my code where if I'm polling something with the mouse, the dialog starts to look 'washed-out' if it goes on for too long (which, is usually no more than a few seconds..!). Sometimes it disappears altogether.

    I'm sure I've read this somewhere before, but can't find any link or reference to it as I don't recall what terms were used. How do we navigate this?

    Cheers,

    WP.

    Most likely what you see is Windows' way of showing you that the app doesn't respond the events - as you're blocking the app with your polling.

    Please avoid that and don't use polling - the GUI is event based and you should program that way (polling for a few milliseconds might be tolerable although its already wasting cpu time and other plugins time, but polling for second or longer ain't).

    Best regards,

    Wilfried



  • On 07/07/2014 at 20:08, xxxxxxxx wrote:

    Thanks Wilfried. For some reason I thought I had read somewhere that there was a way around this by flushing something. I've either mis-read it, or it was to-do with something else altogether.
     
    This leaves me a little blank though. Does this mean we're not able to do something like the following because it's redrawing the user area (and thus the gui)?

    Bool My_User_Area::InputEvent(const BaseContainer& msg)
    {
        BaseContainer bc;
     
        if(GetInputState(BFM_INPUT_MOUSE,BFM_INPUT_MOUSELEFT,bc) && bc.GetBool(BFM_INPUT_VALUE) == 1)
        {
            while(GetInputState(BFM_INPUT_MOUSE,BFM_INPUT_MOUSELEFT,bc))
            {
                if(bc.GetBool(BFM_INPUT_VALUE) == 0)
                {
                    return TRUE;
                }
     
                // get and use mouse coordinates to change something
     
                Redraw(FALSE);
            }
        }
     
        return TRUE;
    }
    

    WP.



  • On 07/07/2014 at 20:20, xxxxxxxx wrote:

    Oh, hang on. Is KillEvents() what I'm looking for here??
     
    WP.



  • On 23/07/2014 at 19:30, xxxxxxxx wrote:

    Hi All,

    Bare with me on this one, I'm in need of some clear clarification.

    1. When can we poll the mouse, and when can't we?
    2. What is KillEvents() for, and when should we use it?
    3. How do we properly handle a mouse drag?
    4. Is there a clean example of mouse dragging somewhere I can look at?
    5. Point 5 below..

    The docs are really unhelpful with all of this. I'll put forward an example of the way I'm currently going about it. The following is a stripped version of what I have when going from one user area to another:

      
    // USER AREA 1 - DRAG STARTER - fired from user area's InputEvent()   
      
    while(GetInputState(BFM_INPUT_MOUSE,BFM_INPUT_MOUSELEFT,MB))   
    {   
        if(MB.GetLong(BFM_INPUT_VALUE) == 0)   
        {   
            return TRUE;   
        }   
      
        // (GET MOUSE COORDS HERE..)   
        // IF MOUSE LEAVES USER AREA,   
        // OPEN A HandleMouseDrag()   
      
        if((MouseX < 0 || MouseX > Width) || (MouseY < 0 || MouseY > Height))   
        {   
            HandleMouseDrag(..);   
        }   
      
        Redraw(FALSE);   
    }   
      
    //--------------------------------------------------------------   
      
    // USER AREA 2 - DRAG RECEIVER   
      
    Message(const BaseContainer &msg;,BaseContainer &result;)   
    {   
        //...   
        case BFM_DRAGRECEIVE:   
        {   
            InputEvent(msg); // second user area does nothing without this   
            break;   
        }   
        //...   
    }   
      
    InputEvent(const BaseContainer &msg;)   
    {   
        //...   
        case BFM_DRAGRECEIVE:   
        {   
            while(GetInputState(BFM_INPUT_MOUSE,BFM_INPUT_MOUSELEFT,LMB))   
            {   
                if(LMB.GetBool(BFM_INPUT_VALUE) == 0)   
                {   
                   return TRUE;   
                }   
      
                // do something.. get mouse coords..   
      
                Redraw(FALSE);   
            }   
      
            return TRUE;   
        }   
        //...   
    }   
    

    In the above example, I'm polling the mouse in the first user area's InputEvent() and calling HandleMouseDrag() when the mouse leaves the area. I'm then waiting for the second user area to receive the BFM_DRAGRECEIVE message, and are initiating the second user areas InputEvent() from the message case. The above example 'works', but the problem is that the second user area is filling up memory with what's probably messages (is this assumption right?). Using KillEvents() fixes the window from greying out, but it does not fix the memory build up. I'm not talking a few megabytes either, I'm talking gigabytes - several gigabytes in a few seconds.

    The other thing also is the mouse cursor. Without polling the mouse in the second user area, the cursor does not stay to what I set it too. It just flickers between two cursor icons.

    5. Are we meant to/allowed to poll, or not?

    Would really appreciate a working example of how to properly handle a mouse drag from one user area to another. Searching the forum only brings up topics with similar queries and incomplete answers.

    Cheers,

    WP.

    P.s. how do we get rid of this rubbish double-line spacing in the code brackets too?


Log in to reply