Miniwindows not deleting as intended

Posted by LezChap on Sat 28 May 2011 08:27 PM — 4 posts, 19,745 views.

#0
A change in version 4.73 has caused the behavior of two of my plugins which use multiple miniwindows in the same location to behave differently. It appears as though a miniwindow is not deleting as intended.

The simpler plugin which is behaving oddly is as follows:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Sunday, February 21, 2010, 8:40 PM -->
<!-- MuClient version 4.43 -->

<!-- Plugin "EmoteLegend" generated by Plugin Wizard -->

<muclient>
<plugin
   name="EmoteLegend"
   author="Josh/Armyboy"
   id="cd8fc0acb178fa8f541f0d93"
   language="Lua"
   purpose="Provides a Legend for the Emote Syntax in Armageddon"
   date_written="2010-02-21 20:39:30"
   requires="4.43"
   version="1.0"
   >
<description trim="y">
<![CDATA[
Creates a small legend in the lower right hand corner with all the emote symbols that Armageddon MUD uses.  Starts Minimize.  Click the double arrow to expand.
]]>
</description>

</plugin>


<!--  Get our standard constants -->

<include name="constants.lua"/>

<!--  Script  -->


<script>
<![CDATA[
function MainWindow()
  win = GetPluginID ()
  EmoteKey = {
      [1]  =  "Sym  Reference  Target",
  	  [2]  =  " ~   (sdesc)     you",
	  [3]  =  " !    him        you",
	  [4]  =  " %   (sdesc)'s   your",
	  [5]  =  " ^    his        your",
	  [6]  =  " #    he         you",
	  [7]  =  " &    himself    yourself",
	  [8]  =  " =   (sdesc)'s   yours",
	  [9]  =  " +    his        yours",
	  }
  WindowCreate(win, 0, 0, 185, 145, 8, 0, 986895)
  WindowLine(win, 0, 0, 195, 0, 14737632, 2, 1)
  WindowLine(win, 0, 0, 0, 160, 14737632, 2, 1)
  WindowFont(win, "f", "Courier New", 9, false, false, false, false)
  WindowFont(win, "b", "Courier New", 12, true, false, false, false)
  WindowFont(win, "u", "Courier New", 9, true, false, true, false)
  top = 2
  height = WindowFontInfo (win, "f", 1)
  for i,v in ipairs(EmoteKey) do
    if i ==  1 then
	  WindowText(win, "u", v, 4, top, 0, 0, 16053492, false)
	else
      WindowText(win, "f", v, 4, top, 0, 0, 16053492, false)
	end
	top = top + height
  end
  MinW = WindowTextWidth(win, "b", "»", false)
  MinL = WindowInfo(win, 3) - MinW - 5
  MinT = WindowInfo(win, 4) - height - 5
  MinR = WindowInfo(win, 3)
  MinB = WindowInfo(win, 4)
  WindowText(win, "b", "»", MinL, MinT, MinR, MinB, 11053224, false)
  WindowAddHotspot(win, "Minimize", MinL, MinT, MinR, MinB,
                   "",   --mouseover
                   "",   --cancelmouseover
                   "",   --mousedown
                   "",   --cancelmousedown
                   "mouseup",   --mouseup
                   "Minimize this window",
			   	   1, 0)
WindowShow (win, True)
end --MainWindow


function mouseup(flags, hotspot_id)
  local action = {
    ["Minimize"] =    function () Minimize()           end,
    ["Show"] =        function () WindowDelete(win2)
                        WindowShow(win, true)           end,
  }
  action[hotspot_id]()
end --mouseup


function Minimize()                                --minimize the big window
  WindowShow(win, false)
  win2 = GetPluginID().."2"
  WindowCreate(win2, 0, 0, 1, 1, 8, 0, 986895)
  WindowFont(win2, "b", "Courier New", 12, true, false, false, false)
  Height = WindowFontInfo (win2, "b", 1)
  local WinH = Height + 2
  local WinW = WindowTextWidth(win2, "b", "« ", false)
  WindowCreate(win2, 0, 0, WinW, WinH, 8, 0, 986895)
  WindowLine(win2, 0, 0, 0, WinH, 14737632, 2, 1)
  WindowLine(win2, 0, 0, WinW, 0, 14737632, 2, 1)
  local MaxL = 0
  local MaxT = 0
  local MaxR = WinW
  local MaxB = WinH
  WindowText(win2, "b", "«",
             MaxL+4, MaxT, 0, 0,
             11053224, false)
  WindowAddHotspot(win2, "Show", MaxL, MaxT, MaxR, MaxB,
                   "",   --mouseover
                   "",   --cancelmouseover
                   "",   --mousedown
                   "",   --cancelmousedown
                   "mouseup",   --mouseup
                   "Expand to see the Emote Symbol Key",
                   1, 0)
  WindowShow(win2, true)
end --Minimize


MainWindow()
Minimize()
]]>
</script>


<!--  Plugin help  -->

<aliases>
  <alias
   script="OnHelp"
   match="EmoteLegend:help"
   enabled="y"
  >
  </alias>
</aliases>

<script>
<![CDATA[
function OnHelp ()
  world.Note (world.GetPluginInfo (world.GetPluginID (), 3))
end
]]>
</script> 

</muclient>

There's a hotspot on the lower right which allows you to "minimize" the window by setting WindowShow to false, and creates a second miniwindow with a hotspot allowing you to maximize the miniwindow. When you click the hotspot to "show" the main window again, it's supposed to delete the second miniwindow, and sets WindowShow to true on the first one.

In 4.72, this plugin (and one that uses the same mechanism to show/hide) works as intended. When you upgrade to 4.73, it appears as if the second miniwindow never deletes as it's supposed to, and ends up being permanently displayed over the main window.

I hope my explanation of what's happening makes sense. If not, take the plugin for a test drive and it should be easy enough to see.

As this is a change to the plugin behavior in previous versions, and I don't see anything in the release notes that this change is intentional, I'm assuming this is a bug. Hope I've provided enough to track it down.
USA Global Moderator #1
Template:post=11047
Please see the forum thread: http://gammon.com.au/forum/?id=11047.


Miniwindows deleting themselves wasn't safe, so Nick made it impossible to try. That is actually in the release notes for 4.73. A more compatible solution to that problem *might* be to mimic the change from the recent discussion on cancelmouseover ordering here:
http://mushclient.com/forum/bbshowpost.php?id=11139
But I haven't really thought about it much.
In the meantime, I think you can safely either use doafterspecial or use a method other than deletion.
Amended on Sat 28 May 2011 09:14 PM by Fiendish
Australia Forum Administrator #2
Yes he's right. Deleting yourself is unsafe and might lead to random crashes. Then I get complaints the client is flaky.

Either do the delete on a timer (could be 0.1 seconds) or just hide it instead.
#3
Nick Gammon said:

Yes he's right. Deleting yourself is unsafe and might lead to random crashes. Then I get complaints the client is flaky.

Either do the delete on a timer (could be 0.1 seconds) or just hide it instead.


I did the latter...went through and fixed the plugins that used the unsafe code (even if I never had nor heard of a problem with it in my plugins). Yay for cleaner code?