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 ➜ General ➜ What is the root cause the "bad magic" exception?

What is the root cause the "bad magic" exception?

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


Posted by Wanghom8228   (19 posts)  Bio
Date Mon 07 Jun 2010 03:41 AM (UTC)
Message
My MushClient crash sometime, but I cannot find a stable repro. When i attach to the crashed process, i saw a error dialog in MushClient pop up and said "bad magic".
I found some information at http://www.gammon.com.au/pcre/pcreapi.html about "Bad Magic" exception.

//=========================================================//
PCRE_ERROR_BADMAGIC the "magic number" was not found

The "magic number" is placed at the start of each compiled pattern as an simple check against passing an arbitrary memory pointer. Here is a typical call of pcre_fullinfo(), to obtain the length of the compiled pattern:

//=========================================================//

But I am not very understand what is the problem and how to resolve it.
Can someone help me understand what is the root cause of "bad magic"? I can fix the issue accordingly.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #1 on Mon 07 Jun 2010 03:46 AM (UTC)
Message
Sounds like a corrupted PCRE compiled pattern. When a regular expression is compiled (from the text you supply) it would put a "magic number" at the start as confirmation there is a genuine pattern there.

Is this just a normal trigger or alias, or are you using the PCRE library inside scripting?

- Nick Gammon

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

Posted by Wanghom8228   (19 posts)  Bio
Date Reply #2 on Mon 07 Jun 2010 05:23 AM (UTC)
Message
Thanks Nick.

I am using the dynamic trigger which is created by AddTriggerEx(). I have my own wrap method like:

function RunWhen(name, match, script)
check (world.AddTriggerEx(
name,
match,
script,
trigger_flag.Enabled + trigger_flag.RegularExpression +
trigger_flag.Temporary + trigger_flag.Replace +
trigger_flag.OneShot,
custom_colour.NoChange,
0, -- Don't copy wildcard to clipboard
"",
"",
sendto.script,
100))
end -- RunWhen

The most suspiciou script is:
ScriptUtility.RunWhen("TR_FJ_SearchFinish", "^(?:> )*SetVariableFGPS = \\\"GoFinish\\\"$", "OnSearchFinish()")

I will call the script above multi-times in my lua.

More questions for you.
1. When the expression will be complied? When the trigger is created or evaluated?
2. Why it will crash my MuchClient, is there anyway to eat the exception?
3. I usually call this RunWhen multi-time without delete the orginal trigger. Is it correct usage?

Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #3 on Mon 07 Jun 2010 05:53 AM (UTC)
Message
The expression is compiled when the trigger is created, to check it is valid. If you have "expand variables" set (which you don't seem to have) then it is compiled again each time (that is, for each line) so that the expanded variables can be substituted in it.

There isn't a way of catching a MUSHclient crash per se. It would be better to work out what is causing it. Are you saying the error dialog pops up saying "bad magic" and then, after you dismiss it, it immediately crashes? Maybe there is some bug in what it does after putting up the dialog.

In your code I note that there seems to be a strange character here:


SetVariable?FGPS


Where the "?" is, seems to be hex 0x81. Is this intentional?

You don't need to delete the original trigger if you use the trigger_flag.Replace flag.

You shouldn't really need to create triggers many times. Is there not a more efficient way? For example, just enabling or disabling an existing trigger? Or if the text changes, using the "expand variables" approach?

What version of MUSHclient are you using?

- Nick Gammon

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

Posted by Wanghom8228   (19 posts)  Bio
Date Reply #4 on Mon 07 Jun 2010 08:36 AM (UTC)

Amended on Mon 07 Jun 2010 10:48 AM (UTC) by Wanghom8228

Message
I am using MushClient 4.43.
Please ignore 0x81, it is some chinese character. And I didn't use the expand variables in my trigger.
The crashing behavior is very interesting. It crashed in my Win7, I select the debug and attach a VisualStudio 2010. The error dialog of "bad magic" pop up. I stop the debug, it crash again. :(
I didn't try WinDBG to go further, probably I will try when I have time and it crash again.

The reason I need to use the dynamic creating trigger is:
I group all the trigger/alias/script in one plugin. Sometimes I need to tuneoff all the functionality of one or more plugin. By using temp trigger, we can easily disable the plugin then delete all temp trigger.

On the other hand, seems MC don't have a UI for plugin edit. Handle most of trigger in script is more easy to me.

I actually didn't see performance issue of deleting/creating the trigger dynamically. How difference between delete/create and enable/disable?
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #5 on Mon 07 Jun 2010 09:41 AM (UTC)
Message
Wanghom8228 said:

I actually didn't see performance issue of deleting/creating the trigger dynamically. How different between delete/create and enable/disable?


I don't think there would be a huge difference.

Try upgrading to version 4.51:

http://www.gammon.com.au/forum/?id=10141

Version 4.45 upgraded the PCRE library which "fixes various bugs" - maybe yours is one of them.

- Nick Gammon

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

Posted by Wanghom8228   (19 posts)  Bio
Date Reply #6 on Mon 07 Jun 2010 10:55 AM (UTC)
Message
Thanks a lot Nick~
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.


24,913 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.