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 


Access violation when trying to create timer inside a thread

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
sgsgwv$6263
Advanced Cheater
Reputation: 0

Joined: 05 Aug 2020
Posts: 75

PostPosted: Sat May 13, 2023 1:04 am    Post subject: Access violation when trying to create timer inside a thread Reply with quote

Whenever I try to create a timer inside a new thread in a script I get an access violation error message.

Is it possible to do what I am trying to do or the access violation might be for something else?
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4289

PostPosted: Sat May 13, 2023 10:46 am    Post subject: Reply with quote

Timers are related to the GUI. They need to be created and accessed in the main thread. Use `synchronize`
_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
sgsgwv$6263
Advanced Cheater
Reputation: 0

Joined: 05 Aug 2020
Posts: 75

PostPosted: Sat May 13, 2023 11:06 am    Post subject: Reply with quote

But that defeats the purpose of creating a seperate thread since it will block till the functions returns. But that function is creating a timer. What will happen to the timer after the function returns.

I am in a situation where I want the timer to run very fast like 50 milliseconds. But I also have a hotkey setup which because of the timer is (what I assume) reacting slowly. So i thought maybe creating a new thread will be beneficial. ChatGPt suggests using queue(). What do you think?
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1247

PostPosted: Sat May 13, 2023 11:49 am    Post subject: Reply with quote

sgsgwv$6263 wrote:
What will happen to the timer after the function returns.


Code:
timer.Destroy() -- timer = your timer name..


If your hotkey is slow to access, place another test in the existing code (Pass or fail, code value, changes in address, etc.) and the hotkey option can stay as a cookie next to them.

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
sgsgwv$6263
Advanced Cheater
Reputation: 0

Joined: 05 Aug 2020
Posts: 75

PostPosted: Sat May 13, 2023 11:54 am    Post subject: Reply with quote

Got a workaround. Instead of creating an explicit timer I can implement a timer on the new thread with infinite while loops with sleep() in it for interval timing. Since this is not a cheat engine timer so will not cause access violation or block the main thread.
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1247

PostPosted: Sat May 13, 2023 12:08 pm    Post subject: Reply with quote

Intermittent Sleep() and "Infinite Loop", that sounds more dangerous. Shocked

Consider a solution where you are in control.

But still, the decision is yours.

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4289

PostPosted: Sat May 13, 2023 3:01 pm    Post subject: Reply with quote

The separate thread is being used to avoid relying on pascal timers.

A while loop and a call to `sleep` in a separate thread is what should be done. Remember to check the Terminated property of the thread.
(even though the Lua interpreter is single threaded, CE doesn't need to lock a mutex to call `sleep` from Lua, so this is fine)

`sleep` shouldn't be called in the main thread to avoid freezing the GUI. In a separate thread, it's perfectly fine.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
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