Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Async exec w/ Form(Designer): invalid window handle [Solved]

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
paul44
Expert Cheater
Reputation: 2

Joined: 20 Jul 2017
Posts: 152

PostPosted: Tue Oct 26, 2021 11:17 am    Post subject: Async exec w/ Form(Designer): invalid window handle [Solved] Reply with quote

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
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1053
Location: 0x90

PostPosted: Tue Oct 26, 2021 11:34 am    Post subject: Reply with quote

It appears that there isn't any access to the handle of the form in the asynchronous thread.
Back to top
View user's profile Send private message
paul44
Expert Cheater
Reputation: 2

Joined: 20 Jul 2017
Posts: 152

PostPosted: Tue Oct 26, 2021 12:19 pm    Post subject: window handle... Reply with quote

^ 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
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

Joined: 09 May 2003
Posts: 25262
Location: The netherlands

PostPosted: Tue Oct 26, 2021 12:46 pm    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
panraven
Grandmaster Cheater
Reputation: 55

Joined: 01 Oct 2008
Posts: 941

PostPosted: Tue Oct 26, 2021 2:39 pm    Post subject: Reply with quote

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
View user's profile Send private message
paul44
Expert Cheater
Reputation: 2

Joined: 20 Jul 2017
Posts: 152

PostPosted: Wed Oct 27, 2021 12:15 pm    Post subject: Solved... Reply with quote

^ @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 Embarassed

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites