View previous topic :: View next topic |
Author |
Message |
DaSpamer Grandmaster Cheater Supreme Reputation: 52
Joined: 13 Sep 2011 Posts: 1578
|
Posted: Thu Mar 13, 2014 12:06 pm Post subject: Problem with canvas when using createNativeThread. |
|
|
Hey,
When I use createNativeThread to render pixels it does not operate well, it skips 'pixels' only if I slow it down it starting to work bit better.
If code of what I'm doing is needed message me (650 kb file... with 2 images parsed as tables). _________________
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25295 Location: The netherlands
|
Posted: Thu Mar 13, 2014 12:19 pm Post subject: |
|
|
Do not access the gui from other threads. Use threadobject.synchronize(function) to call the gui code in the main thread
You are free to render to your own bitmap object using threads and then display that on the canvas using the main 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 |
|
|
DaSpamer Grandmaster Cheater Supreme Reputation: 52
Joined: 13 Sep 2011 Posts: 1578
|
Posted: Thu Mar 13, 2014 12:28 pm Post subject: |
|
|
I was updating the pixels..
And when updating it kinda slows down the program a lot.
Code: | createNativeThread( function (selfThread)
while 1==1 do
if not revert then
if (math.random()>=0.80) then
mix2 = not mix2;
end
counter = 0;
for i,table in pairs(Flashacking_IMG2) do
local Table =Flashacking_IMG2[i]
for _,color in pairs(Table) do
for x=_,_+ 8 do
if x<=#Table then
local color
if mix2 then
color = ColorTable_1[Table[x]]
else
color = ColorTable_2[Table[x]]
end
if color~=16777215 then
canvas_setPixel(canvas, i, x, color)
end
end
end
if (counter == 5) then
sleep(1); -- to slow down a bit, and avoiding skips
counter = 0;
end
counter = counter + 1;
end
end
revert = not revert;
end
end
end); |
_________________
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25295 Location: The netherlands
|
Posted: Thu Mar 13, 2014 1:58 pm Post subject: |
|
|
yeah, don't call any gui related functions inside a thread
Flashacking_IMG2 is a gui object, and the canvas is belong to that image, so it turns into a gui call
what you could try instead is create a bitmap of the same size as as the TImage object (bmp=createBitmap(Flashacking_IMG2.Width, Flashacking_IMG2.Height)
then render to that bmp's canvas which is off-screen, so no gui, and when done render the image to the gui using the gui thread
example:
Code: |
--create an offscreen bitmap
if bmp==nil then
bmp=createBitmap(Flashacking.IMG2.Width,Flashacking.IMG2.Height)
end
bmp.Canvas.Brush.Color=0x000000
bmp.Canvas.clear()
function present()
--called from the main thread
Flashacking.IMG2.Canvas.draw(0,0,bmp)
end
function drawthread(self)
local i
math.randomseed( os.time() )
while 1==1 do
for i=1, 10 do --you can make this take as long as you wish, it won't block the gui (just lowers the framerate)
bmp.Canvas.setPixel(math.random()*Flashacking.IMG2.Width, math.random()*Flashacking.IMG2.Height, math.random(0xffffff))
end
--present the image
thread_synchronize(self, present) --self.synchronize doesn't work in 6.3, but will in 6.3+
--optionally
--bmp.Canvas.clear()
end
end
createNativeThread(drawthread)
|
_________________
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 |
|
|
DaSpamer Grandmaster Cheater Supreme Reputation: 52
Joined: 13 Sep 2011 Posts: 1578
|
Posted: Thu Mar 13, 2014 2:47 pm Post subject: |
|
|
Thanks for the example.
Wasn't sure exactly about the bitmap, but now that I am, It'll help me a lot!!. _________________
|
|
Back to top |
|
|
|