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.