|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Sat Aug 16, 2014 10:54 am Post subject: native thread and timer |
|
|
I have very long Lua script. It works great.
But it has one downside: I have to use openProcess in a loop, and this instruction freezes CE (micro stuttering while form dragging, or scrolling my NFO window).
So, I moved this loop into another function, function assigned to native thread (created with createNativeThread).
But, another problem arise: looks like a can not enable timer object in native thread.
Here, I wrote another script you can test this issue:
Code: | function smrtDestroy(o) if o and o.destroy then o.destroy() end end
smrtDestroy(testTimer); testTimer=nil
testTimer = createTimer(nil,false)
testTimer.Interval = 1000
testTimer.OnTimer = function (timer) print("testTimer tick") end
function tTest(thread)
thread.name = 'tTest'
print('tTest thread started')
while not allow do
sleep(1000)
end
testTimer.Enabled = true
print('testTimer should work')
end
createNativeThread(tTest) |
Launch this script,
then, in Lua Engine window, execute this:
Output is:
Code: | tTest thread started
allow = true
testTimer should work |
I expected "testTimer tick" as well, but it doesn't show up.
EDIT:
I could change this line
testTimer.Enabled = true
into
thread.synchronize(function () testTimer.Enabled = true end)
But, it looks weird. Is there other solution?
_________________
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 457
Joined: 09 May 2003 Posts: 25262 Location: The netherlands
|
Posted: Sat Aug 16, 2014 6:56 pm Post subject: |
|
|
Not sure. The timer falls in the "gui" category, so it's to be expected to be buggy when used in a thread, but it's so low level there shouldn't be too many issues.
Instead of setting enabled to true, try creating it enabled by default, but keep OnTimer unassigned (or point it to an empty function)
In the thread then assign the timer an OnTimer event . This might work better as it's less unsafe (still 2 pointers, code and data)
The "official" solution is to use synchronize though
_________________
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 |
|
|
|
|
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
|
|