[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Bug reports
. . -> [Subject]  Crash in version 4.03!

Crash in version 4.03!

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


Pages: 1  2 

Posted by Nick Gammon   Australia  (23,016 posts)  [Biography] bio   Forum Administrator
Date Reply #15 on Wed 18 Apr 2007 04:06 PM (UTC)
Message
I think I have found it. There was an obscure problem with a CString object, which was statically declared, not correctly decrementing its reference count under certain circumstances. This part of the code has been reworked, and it seems to run reliably now.

As far as I could see you could trigger it by adding a plugin, which had a state file, and then closing the world.

The code was part of the stuff introduced in version 4.03 to fix the "wrong directory" problem that Shadowfyr had been talking about.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Shadowfyr   USA  (1,786 posts)  [Biography] bio
Date Reply #16 on Wed 18 Apr 2007 06:53 PM (UTC)
Message
Ok.. I have narrowed the problem down to the "main" script file. When I disable script, the problem goes away, so the issue in with the main script. Now.. I use several callbacks in that script for connecting and disconnecting, some color changing code for some stuff in there, etc. What ever the problem is, its in there. My guess is that the problem is someplace "in" the code for closing a connection:

sub Terminate
  save ""
  if getvariable ("AReconnect") = "ON" then
    aa = now
    do
      cc = abs(datediff("s",aa,now))
    loop until cc > 1
    connect
  else
    if getvariable("ResetND") = "True" then 
      setvariable "FinalTime", -1
      if isplugininstalled("b5a12674355d40240455d8a1") then
        callplugin "b5a12674355d40240455d8a1","ResetIcons","Null"
      end if
    end if
  end if  
end sub


Though, I don't see anything in there that should be doing that. There isn't any other code I know of that should be called on disconnecting...

The "connect" code is:

sub Start
  setvariable "QuitSW", "OFF"
  setvariable "Stored","YES"
  setvariable "ResetND","False"
  NotecolourRGB &hFF9E3E, &h00
  if cint(getvariable("FinalTime")) = -1 or datediff ("s",getvariable("CurConTime"),now) > 28800 then
    hr = 2
    setvariable "FinalTime", hr * 60 * 60 '14400 = 4
    setvariable "CurConTime", now
    resettimer "ShowTime"
  end if
  setvariable "SExp", 0
  setvariable "LExpAvg",0
end sub


I also have the callback for "Close" set:

sub Close_World
  set winamp = Nothing
  setvariable "FinalTime", -1
end sub


But that can't be the problem, since I am not closing the world when merely disconnecting.

Now, obviously, since this happens even if I send the server aliased "xyzzq" command, its not anything called by an alias that is doing this. That still leaves a big chunk of code that deals with updating the status bar that does happen constantly when connected too. Nearly 1/4 all the code in my main script deals with that. The rest is miscelanious stuff that I haven't bothered to move to a plugin.

Hmm. Is there something wrong with 'save ""' now maybe? Let me check on that.
[Go to top] top

Posted by Shadowfyr   USA  (1,786 posts)  [Biography] bio
Date Reply #17 on Wed 18 Apr 2007 06:55 PM (UTC)
Message
***Yes!!!*** Its the line that has 'save ""' in it. That is crashing the client. When that line is commented out, it doesn't crash at all. That narrow enough for you? lol
[Go to top] top

Posted by Shadowfyr   USA  (1,786 posts)  [Biography] bio
Date Reply #18 on Wed 18 Apr 2007 06:57 PM (UTC)
Message
Bah.. You fixed it before I had a chance to hunt the problem down. lol But yeah, I kind of suspected it might be in the new code for the directory paths, which makes sense given what was crashing it.
[Go to top] top

Posted by Nick Gammon   Australia  (23,016 posts)  [Biography] bio   Forum Administrator
Date Reply #19 on Wed 18 Apr 2007 09:27 PM (UTC)
Message
Thank you for narrowing it down. At least that confirms my analysis. Hopefully you will also find that 4.04 works correctly.

For anyone interested, I think the roots of this problem go the problem of a race condition between statically-created classes. Take for example:


(File A.cpp)

someClass X;

------- (and in another source file)  -------

(File B.cpp)

someOtherClass Y;



Now if X and Y are outside any function they are "static" - that is they reside in main memory and not on the stack of any particular function call.

Let us assume that Y uses X in some way. For example, X is a string, and Y is something that requires knowledge of X. For example X is some global thing (like, a default directory).

Now we have the question of the construction order. Since X and Y are not inside a function they must be constructed at program startup time. Let's assume that the way things are linked together all the constructors for file A are called first. Thus, X is constructed (and is now valid), and then Y is constructed. So far, so good. When X refers to Y, Y is valid. We already have a problem if the order was reversed, because Y would use X before X became valid.

Even so, we have a problem with destructors. Assuming the compiler calls destructors in the same order (File A and then File B), then X is destroyed first, and then Y. However Y needs X and crashes when it tries to use the (now destroyed) X.

I think the problem does not exist with classes in the same compiled file, because the compiler is smart enough to maintain a list of all the static classes in that file, and call the destructors in reverse order to the constructors. Thus it would destroy Y and then X, which would be OK in this case.

This sort of bug is particularly insidious, because in a sense the programmer hasn't done anything "wrong", and what has been done would be OK in a single source file.

I *think* this is the root of the problem, however I also read about another possible problem, that with statically created classes (like strings), that if you happen to create them in one place, but use them in another place (like a DLL), then the DLL uses a different memory space to the main program, and the memory allocation is done in the wrong place. The script engine (VBscript in this case) runs in a DLL, so possibly the call to a function in the main program, which happened to use a static string, was to blame.

In any case, the code in question has been reworked to not use a statically declared string. :-)

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Shadowfyr   USA  (1,786 posts)  [Biography] bio
Date Reply #20 on Thu 19 Apr 2007 06:46 PM (UTC)
Message
How fun.. lol But, I don't think it was the memory address issue, but the X then Y, so Y then X one. It was crashing even if I just clicked the "save" button on the toolbar. :( Its working correctly now.
[Go to top] 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.


55,939 views.

This is page 2, subject is 2 pages long:  [Previous page]  1  2 

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]