SRL Archive - General

SCAR Common Error (Solution)


Freddy1990

2007-11-05 17:56:23

Hello there,

I've recently been wondering what causes a series of inexplicable errors which occur while running a script. Now I've become aware of the fact that this is due to the script engine being thread-unsafe. This basically means that when accessing something in anotehr thread there's a change (which is higher for writing values than reading them) that access violation errors will occur. This happens most commonly when accessing the GUI thread. This means most of the form interactions and GetSelf/GetApplication usage (where any form would be accessed, not for like MessageBox). This can be resolved by using the ThreadSafeCall function. For example, when you wish to place a value in a TEdit on a form created by your script, it is best to create a function which places the value into it and a function using the ThreadSafeCall function to access it. Though errors will not occur every time a property is read or written to, the chance does exist and it might occur on later times. (This is also the reason why form initialization functions are ran trough ThreadSafeCall, it writes many values to the form, which makes it a high-risk situation).

I'm currently planning on attempting to build thread-safety into the scriptengine, but until I do it's suggested to use ThreadSafeCalls as much as possible, ESPECIALLY when writing values to form controls.

(NOTE* The movetotray bug is not caused by this)

IronTeapot

2007-11-05 19:26:28

THANK YOU! This had been happening everytime I called things in the GUI to read anf write into edit fields / rs screen. It was starting to drive me nuts. A question though, how do you wrtie 'ThreadSafeCall' functions for internal GUI components. Is it done the same as then doing a ThreadSafeCall for the whole forum? WOuld you be able to give an example, say for getting txt from an edit field, and typing it to the activated screen(notepad, rs, etc.)

Smartzkid

2007-11-05 19:34:26

That would be extremely nice, and greatly appreciated, Freddy.

Just to verify something…this won't get SCAR any closer to script-controlled multithreading, will it?

IronTeapot

2007-11-05 19:39:50

*Drool* multi threading… if only a dream come true. InterScarMessaging is the closest to multithreading. though it has to wait to be called from the main script before it can be used. how great would it be to have a randoms check keep an eye out while youre doing anything, or to keep an eye on active objects and click a new tree just when the old one is cut down.

mastaraymond

2007-11-06 10:41:49

From: Smartzkid
That would be extremely nice, and greatly appreciated, Freddy.

Just to verify something…this won't get SCAR any closer to script-controlled multithreading, will it?


No the scar engine just doesn't allow it, although you can do it with plugins. But i doubt there ever would be a SCAR with multithreading unless Freddy remakes the whole engine, which i doubt ^^.

Freddy1990

2007-11-06 11:09:20

From: IronTeapot
THANK YOU! This had been happening every time I called things in the GUI to read anf write into edit fields / rs screen. It was starting to drive me nuts. A question though, how do you write 'ThreadSafeCall' functions for internal GUI components. Is it done the same as then doing a ThreadSafeCall for the whole forum? Would you be able to give an example, say for getting txt from an edit field, and typing it to the activated screen(notepad, rs, etc.)


Yeah, just pass any function in your script to the ThreadSafeCall with a variantarray containing it's parameters.


And this wouldn't get it any closer to multithreading, the engine just isn't built for that…

fert

2007-11-11 00:35:21

lol i couldnt understand that conversation.
To much scripting language
*must….not…..be…..noob….ugh