Jump to content


Photo

Gmthreads 2 [updated: 30 Dec 2009]


  • Please log in to reply
204 replies to this topic

#161 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • Retired Staff
  • 9314 posts
  • Version:Unknown

Posted 14 March 2010 - 05:50 AM

I found the problem...sort of. I said I wasn't drawing any of the sprites in use because I only drew them after the thread was finished and closed. I figured they're no longer in use, so they should be normal sprites now.

I guess even after closing the thread, it continues running for a bit. Which is weird, because here's the code I used to decide when to close the thread (the variable "running" is set to 1 when the thread is resumed):

if (!thread_is_running(thread) and running) {
running=0;
thread_close(thread);
exit;
}
else if (thread_is_running(thread) and !running) { exit; }

It seems the thread stops running, and when you close it it "runs" again for a second. This rerunning is what caused my problem, as I thought the closed thread was no longer using the resources. That last line with the else{} fixed the issue.

Anyone know why this happens?

-IMP :P :)
  • 0

#162 qwertyuiop23

qwertyuiop23

    GMC Member

  • New Member
  • 940 posts

Posted 02 April 2010 - 11:56 PM

Two questions:

1) Could all the drawing functions (3D) in gamemaker be converted into always being run as a thread?
2) Will this speed up a game?

Chur
Qwertyuiop23
  • 0

#163 score_under

score_under

    Least kawaii

  • GMC Member
  • 1319 posts

Posted 03 April 2010 - 01:26 AM

Two questions:

1) Could all the drawing functions (3D) in gamemaker be converted into always being run as a thread?
2) Will this speed up a game?

Chur
Qwertyuiop23

1. Yes, but there's not much point.
2. No, it would slow it down.
There's a time and a place for threads. Individual 3D functions isn't one of them.
  • 0

#164 bigttcool2

bigttcool2

    GMC Member

  • New Member
  • 98 posts

Posted 10 April 2010 - 01:05 AM

How can you get a thread to execute a drawing event?
Is it like the step solution with the while loop?

Thanks. :)
  • 0

#165 score_under

score_under

    Least kawaii

  • GMC Member
  • 1319 posts

Posted 11 April 2010 - 03:22 AM

How can you get a thread to execute a drawing event?

You don't.
You find some way to make *other* code execute in another thread, and to make drawing code execute in the main thread.
  • 0

#166 wargasm

wargasm

    GMC Member

  • GMC Member
  • 189 posts

Posted 14 May 2010 - 06:46 PM

What would cause a thread to apparently stop running/crash? Im using this code, and while it sometimes works, most of the time it doesn't and the thread seems to lock up at different moments when creating the objPoints. When the objPoints are created successfully everything seems to work fine, just most of the time it doesnt succeed in creating all the points for some reason.

thread_init();
my_thread=thread_create("var size,points,gridpoints,lastpoint;
global.particlegrid=part_system_create();
size=2000;
points=40;
x=0;
y=0;
xx=x;
yy=y;
for(i=0;i<points;i+= 1){
for(o=0;o<points;o+=1){
gridpoints[i,o]=instance_create(xx,yy,objPoint);
if(o>0&&o!=points){
lastpoint.nextpoint=gridpoints[i,o];}	  
lastpoint=gridpoints[i,o];
xx+=size/points;}
xx=0;
yy+=size/points;}
while(true){with(objPoint){var vx,vy; 
hspeed+=(xstart-x)/60;
vspeed+=(ystart-y)/60;
dist=point_distance(x,y,nextpoint.x,nextpoint.y);
ang=point_direction(x,y,nextpoint.x,nextpoint.y);
part_type_scale(pt1,dist,1);
part_type_orientation(pt1,ang,ang,0,0,0); 
motion_add(point_direction(mouse_x,mouse_y,x,y),max(0,(300-point_distance(x,y,mouse_x,mouse_y))/60));
friction=speed/60;
part_emitter_region(ps,em,x,x,y,y,ps_shape_rectangle,ps_distr_line
ar);}sleep(5);}",0);

  • 0

#167 wargasm

wargasm

    GMC Member

  • GMC Member
  • 189 posts

Posted 16 May 2010 - 02:00 PM

gridthread = thread_create("while(true){for(i=0;i<points-1;i+=1){for(o=0;o<points-1;o+=1){with(gridpoints[i,o]){part_emitter_region(ps,em,x,x,y,y,ps_shape_rectangle,ps_distr_line
ar);}}} sleep(10);}",0);

The above code works in the step event, but it doesnt set the particle region when used in a thread. Any idea why? Cheers.
  • 0

#168 general sirhc

general sirhc

    YW Creator

  • New Member
  • 1651 posts

Posted 24 May 2010 - 01:48 PM

EDIT: Never mind my entire post was wrong

Edited by general sirhc, 25 May 2010 - 06:55 AM.

  • 0

#169 B Factory LLC

B Factory LLC

    We're awesome!!

  • New Member
  • 511 posts

Posted 03 June 2010 - 07:08 PM

Can you upload a file type other than RAR? We can't open .rar files.
  • 0

#170 Gamer_X

Gamer_X

    GMC Member

  • New Member
  • 18 posts

Posted 03 July 2010 - 09:58 PM

Snake_PL, can i use the dll in a comercial game for free ?


EDITED:

Nevermind, i started using this: (sorry, corrected now)
http://gmc.yoyogames...howtopic=418228

Edited by Gamer_X, 04 July 2010 - 11:23 PM.

  • 0

#171 MrOpposite

MrOpposite

    Yesterdays games

  • New Member
  • 744 posts

Posted 19 July 2010 - 08:48 PM

I think I found a bug:
instance_destroy();

doesn't always work instantaneous. If you destroy an object and later use a with statement with that object, you get an "<game-name-here>.exe has encountered a problem..." error.

I'm not sure of this yet. But I'll test and come back later.
  • 0

#172 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 19 July 2010 - 09:05 PM

That could cause an access violation, depending on how GM works.
  • 0

#173 MrOpposite

MrOpposite

    Yesterdays games

  • New Member
  • 744 posts

Posted 20 July 2010 - 02:22 PM

That could cause an access violation, depending on how GM works.

I'm not sure. But when I use thread_wait directly after creating a thread, I don't get any error. When I allow the thread to run along with the game I sometimes get this "<game>.exe has encoutered an error" error message from windows. Any ideas?

EDIT:
What happens if the thread alters/deletes data to an object that that object tries to access at the same time. Like, if the thread alters the X/Y variables of the player object at the same time the player object access them.

EDIT 2:
Just made some tests, this codes craches the game:
var list;
repeat(argument0)
{
    with(obj_player)
    {
        list = ds_list_create();
        ds_list_add(list,123);
        ds_list_destroy(list);
        if(!floor(random(argument0)))
            instance_destroy();
    }
}

while this doesn't
var list;
repeat(argument0)
{
    with(obj_player)
    {
        list = ds_list_create();
        ds_list_add(list,123);
        ds_list_destroy(list);
    }
}

I'm gonna try with instance creation too.


EDIT 3:
Instance creation doesn't crash either...

EDIT 4:
HOWEVER the creation event doesn't occur directly after the creation function. So if you check for a variable in the step event, sometimes the step event is executed BEFORE the create event of the object were executed as the create event is executed in the thread and the step event is executed in the main game.

EDIT 5:
Ok, so here's whay shou should avoid, and do instead.
DON'T remove any instances while running a thread, not IN the thread, or in the game, it might crash your game.

DO INSTEAD: Mark the object with a variable and move it out of the way. then delete the object when the thread isn't running.

If you create objects in the thread, make sure the creation event has occured in the main game by using "if(variable_local_exists("<varname>"))" and using a variable you create in create event.

Edited by MrOpposite, 20 July 2010 - 04:05 PM.

  • 0

#174 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 20 July 2010 - 08:15 PM

If you destroy an instance from a thread with this while it is being used by the Game Maker thread, then Game Maker will freak out on you. It wasn't made to be threaded, which is why there are many limitations on these threading DLLs. Blame Game Maker.
  • 0

#175 MrOpposite

MrOpposite

    Yesterdays games

  • New Member
  • 744 posts

Posted 20 July 2010 - 08:17 PM

If you destroy an instance from a thread with this while it is being used by the Game Maker thread, then Game Maker will freak out on you. It wasn't made to be threaded, which is why there are many limitations on these threading DLLs. Blame Game Maker.

I know, that's why I wrote Edit 5... That's a working workaround.
  • 0

#176 Seamonster

Seamonster

    Meow!

  • New Member
  • 743 posts

Posted 12 August 2010 - 04:17 PM

Solved it on my own :)
Thanks for the DLL by the way!

Edited by Seamonster, 12 August 2010 - 04:46 PM.

  • 0

#177 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 12 August 2010 - 04:33 PM

Try using string().
  • 0

#178 Primoz128

Primoz128

    GMC Member

  • GMC Member
  • 278 posts
  • Version:GM:Studio

Posted 17 February 2011 - 07:48 AM

I really don't know how to use this or when... Anyone knows when should it be used in a multiplayer project ?
  • 0

#179 johnjoe

johnjoe

    GMC Member

  • New Member
  • 299 posts

Posted 17 February 2011 - 08:21 AM

it could be used in any game type.

the codes are stored within the "", say for example you want to increment a global variable by 1 using the other thread you'd have to insert 'global.thisvariable += 1;' within the quoted parameter brackets along with other codes you want to insert. only global variables can be used, no local variables, no constants either.

so virtually it would look like:

gmthread_run("

global.thisvar += 1
global.thatvar += 1

");
  • 0

#180 Dylan93

Dylan93

    GMC Member

  • GMC Member
  • 866 posts
  • Version:GM8

Posted 17 February 2011 - 08:57 AM

I really don't know how to use this or when... Anyone knows when should it be used in a multiplayer project ?


Just a quick suggestion but: when connecting to a server :), instead of the game freezing you can show/do other things.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users