Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Bug reports ➜ Over 100 resizes and out of order display at startup

Over 100 resizes and out of order display at startup

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Fiendish   USA  (2,535 posts)  Bio   Global Moderator
Date Mon 04 Jul 2011 08:46 PM (UTC)
Message
I just threw this into a plugin loaded at startup to test something:

i = 0
print("hmmm")
function OnPluginWorldOutputResized()
   i = i+1
   print(i)
end


The output I got was this...
Quote:

95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
Welcome to MUSHclient version 4.75!
Written by Nick Gammon.

Compiled: Jun 12 2011.
Using: Lua 5.1.4, PCRE 8.12, PNG 1.5.2, SQLite3 3.7.6.3, Zlib 1.2.5

For information and assistance about MUSHclient visit our forum at:
http://www.gammon.com.au/forum/
Can you trust your plugins? See: http://www.gammon.com.au/security
hmmm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
117
118
119
120
121
122
123


There are two obvious issues here.
First, 123 resizes seems rather excessive.
Second, the output from 95-116 is in the wrong place.

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #1 on Mon 04 Jul 2011 08:50 PM (UTC)
Message
That's Windows for you Fiendish. If I don't pass on the WM_SIZE when I get them when am I supposed to do it?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Fiendish   USA  (2,535 posts)  Bio   Global Moderator
Date Reply #2 on Mon 04 Jul 2011 08:52 PM (UTC)
Message
I guess. Any idea about the ordering weirdness?

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #3 on Mon 04 Jul 2011 09:09 PM (UTC)

Amended on Mon 04 Jul 2011 09:18 PM (UTC) by Twisol

Message
Nick Gammon said:
That's Windows for you Fiendish. If I don't pass on the WM_SIZE when I get them when am I supposed to do it?


Many browsers have the same issue with the onresize event. A common practice is to delay the event by 50-100ms, and if another onresize occurs during that period, the timer is reset. It basically waits until the last onresize has arrived.

function delay(f, time) {
  var id = null;
  return function() {
    var context = this;
    var args = Array.prototype.slice(arguments);
    
    if (id) { window.clearTimeout(id); }
    
    id = window.setTimeout(function() {
      id = null;
      f.apply(context, args);
    }, time);
  };
}

$(window).resize(delay(function() {
  // do stuff
}, 100));


Another approach is to wait 100ms from the first onresize and ignore any others until the time is up, at which point you act on the event and start accepting onresize events again. This guarantees a more regular frequency for handling resize events, since you always respond after 100ms. The first approach ensures that only one onresize is handled.
function wait(f, time) {
  var id = null;
  return function() {
    var context = this;
    var args = Array.prototype.slice(arguments);
    
    if (!id) {
      id = setTimeout(function() {
        id = null;
        f.apply(context, args);
      }, time);
    }
  };
}

$(window).resize(wait(function() {
  // do stuff
}, 100));


I suppose this is similar to "debouncing" in electronics, although in that case the event is handled immediately and there's a cooldown. But that's not really what you want in the resize-event case.

[EDIT]: Code examples! I already had the first written, so I threw it in and added the second.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #4 on Mon 04 Jul 2011 09:29 PM (UTC)
Message
Fiendish said:
I guess. Any idea about the ordering weirdness?

My only guess is that, for 1-94 the output area wasn't initialized, so they were buffered up. For 95-116 they snuck in after initialization but before the first lines were flushed. Right after 116 the buffer was flushed, and 117-123 came out in the right place.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #5 on Tue 05 Jul 2011 05:37 AM (UTC)
Message
Fiendish said:

I guess. Any idea about the ordering weirdness?


Well, Windows posts messages (which get queued), it sends them (which don't) and then you have MFC doing who-knows-what before I get them.

If you are going to "debounce" the sizing you may as well do that yourself. Get the resize callback to start some sort of timer, and if the timer already exists, reset it. Then when the timer finally fires, do what you have to do.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #6 on Tue 05 Jul 2011 05:45 AM (UTC)
Message
Nick Gammon said:

Fiendish said:

I guess. Any idea about the ordering weirdness?


Well, Windows posts messages (which get queued), it sends them (which don't) and then you have MFC doing who-knows-what before I get them.

If you are going to "debounce" the sizing you may as well do that yourself. Get the resize callback to start some sort of timer, and if the timer already exists, reset it. Then when the timer finally fires, do what you have to do.

Fairly sure the issue is about some of the Notes coming out ahead of Notes that fired earlier, not the resizing events quantity.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #7 on Tue 05 Jul 2011 05:49 AM (UTC)
Message
Oh is that what you meant? I though you were referring to the WM_TIMER messages.

In that case, well spotted. It is an artefact of the world initialisation. I probably would have missed that. :)

Well I *did* miss it. ;)

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #8 on Tue 05 Jul 2011 05:51 AM (UTC)
Message
Haha, yeah, the thread was about two separate issues. ;) I was talking about delaying the event handling in my first post, then speculating on the note ordering issue in the one immediately following.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #9 on Tue 05 Jul 2011 05:58 AM (UTC)
Message
Nick Gammon said:

Oh is that what you meant? I though you were referring to the WM_TIMER messages.


Er, WM_SIZE messages.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


27,315 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.