GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2010-05-24 13:15:21

Marchal_Mig12
Member
Registered: 2009-05-21
Posts: 75

Speed Test Bug (instance_activate_*) - SOLVED

Hi,

When trying to see if instance_activate_* functions and instance_deactivate_* functions would have a speed impact while handling many objects, I encountered a little bug I did not expect at all. Here's the code I used to test the speed for those functions:

Expandrepeat(100000)
  instance_create(-500+random(2000),-500+random(2000),objTest);
  
time = current_time;
instance_deactivate_all(true);
instance_activate_region(0,0,640,480,true);
show_message(string(current_time-time));

with(objTest)
  instance_destroy();
  
repeat(10)
  instance_create(-500+random(2000),-500+random(2000),objTest);
  
time = current_time;
instance_deactivate_all(true);
instance_activate_region(0,0,640,480,true);
show_message(string(current_time-time));

with(objTest)
  instance_destroy();

I've put this code into the "press space event" of a controller. objTest is a simple object with a 32*32 black square as sprite. While pressing space the first time, it gives me 32 for both test (100000 and 10 objects). Then, when I press it a second time, it gives me about 60 for both. This number is would always be the same or about the same each time I press space and is increasing also. In other words, after I pressed space 10 times, the time taken to execute the code become about 200 milliseconds which is very strange.

I guess it has something to do with how GM handles memory.

Any thoughts?

Last edited by Marchal_Mig12 (2010-05-24 13:20:49)

Offline

#2 2010-05-24 13:20:36

Marchal_Mig12
Member
Registered: 2009-05-21
Posts: 75

Re: Speed Test Bug (instance_activate_*) - SOLVED

Anyways, I solved it.

Offline

#3 2010-05-25 10:57:58

xot
Administrator
Registered: 2007-08-18
Posts: 1,240

Re: Speed Test Bug (instance_activate_*) - SOLVED

What was the problem?


Abusing forum power since 1986.

Offline

#4 2010-06-05 23:29:06

Marchal_Mig12
Member
Registered: 2009-05-21
Posts: 75

Re: Speed Test Bug (instance_activate_*) - SOLVED

xot wrote:

What was the problem?

I forgot to reactivate objects before destroying them.

Offline

Board footer

Powered by FluxBB