View previous topic :: View next topic |
Author |
Message |
paul44 Expert Cheater Reputation: 2
Joined: 20 Jul 2017 Posts: 152
|
Posted: Tue Oct 26, 2021 11:17 am Post subject: Async exec w/ Form(Designer): invalid window handle [Solved] |
|
|
see example here: [ https://imgur.com/a/XhnSss6 ]
The Lua script shows up a Form (created via FormDesigner, and part of the table). As long as i execute the script in the "normal" way, no problems whatsoever (re-open/close/keep open).
However: if i try to run the same script 'async_exec', then I quickly wind up with that error (see pt a. below). 2 situations:
a. the script has already been set in 'async' mode: you'll see the form "presenting" itself for a flash moment; and then quits...
(if you then try to [Edit] the form, you'll get that error showing)
b. the script is initially set as 'normal': no probs. now change it to 'async' and you will still be able to rerun the script. Close/reload the table and - with 'async' set - you'll back with the error...
Note 1: once the error manifested, you can no longer use that script until a pc reboot (even logoff did not solve it) !
Note 2: in this particular script, a memscan is executed (hence the 'async'), but it also happens to a script, which just loops through a pointer list.
Some questions:
a. is this a know bug ? Possible workarounds/suggestions ?
(I did some reading on similar subjects, but nothing related.)
b. is it possible to de/activate 'async exec' from within Lua script ?
(-EDIT- actually: see MemoryRecord Class)
If you need more details/code/etc, just give a shout
(I've already uploaded several tables using this approach @FRF; mostly AC titles)
Last edited by paul44 on Wed Oct 27, 2021 12:16 pm; edited 2 times in total |
|
Back to top |
|
|
LeFiXER Grandmaster Cheater Supreme Reputation: 20
Joined: 02 Sep 2011 Posts: 1055 Location: 0x90
|
Posted: Tue Oct 26, 2021 11:34 am Post subject: |
|
|
It appears that there isn't any access to the handle of the form in the asynchronous thread.
|
|
Back to top |
|
|
paul44 Expert Cheater Reputation: 2
Joined: 20 Jul 2017 Posts: 152
|
Posted: Tue Oct 26, 2021 12:19 pm Post subject: window handle... |
|
|
^ out of my comfort zone, but the next Q would be: how do i get/manage this winhandle? The async/thread process is initiated by CE - using that particular memRec flag - so i'm assuming that CE also 'handles the hwnd' here...?
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25287 Location: The netherlands
|
Posted: Tue Oct 26, 2021 12:46 pm Post subject: |
|
|
Only the main thread can access GUI objects.
Async routines run inside a different thread, so you can't use those to access the GUI.
But you can let the async thread tell the main GUI thread to execute some code and then continue when that's done
e.g:
Code: |
--thread code
synchronize(function()
UDF1.SomethingVisible.Caption='12345'
end)
--continue with thread code
|
remember, do NOT use any infinite whole loop or sleep inside the main GUI thread
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
panraven Grandmaster Cheater Reputation: 55
Joined: 01 Oct 2008 Posts: 942
|
Posted: Tue Oct 26, 2021 2:39 pm Post subject: |
|
|
This should disable async and retry the memrec, may place before [ENABLE] tag so it run while enabling or disabling
Code: |
{$lua}
if memrec.Async then
synchronize(createTimer,1,function(mr, tostate)
mr.Async = false
mr.Active = tostate
end, memrec, not memrec.Active)
error'retry'
end
{$asm}
|
_________________
- Retarded. |
|
Back to top |
|
|
paul44 Expert Cheater Reputation: 2
Joined: 20 Jul 2017 Posts: 152
|
Posted: Wed Oct 27, 2021 12:15 pm Post subject: Solved... |
|
|
^ @DarkByte: I've implemented your suggestion as it was a) very easy to "integrate" b) not sure about #Panraven's suggestion; probably because i do not understand its concept (if that is the right wording). as I "read" it, it will re/set that flag, but i fail to see how it is "linked" to any 'Form' call.
(might give it a try this weekend though...)
frankly, i already had a hard time understanding that "construct", but luckily he was kind enough to give both versions here: [ https://www.cheatengine.org/forum/viewtopic.php?p=5763510&sid=9b446b9fb152527b4f04bf6f73a97a41 ]...
But still, over my head atm, i'm afraid
fyi:
a) did extensive testing (incl several reboots, and switching between 2 games/tables using async_exec) and still running fine.
b) did a quick check_up on threadmgmt w/ 'Process Explorer'; looks like CE cleans up threads nicely !
|
|
Back to top |
|
|
|