🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

GC/reference errors when adding function handle delegates to array

Started by
3 comments, last by cmann 3 years, 10 months ago

So just like the title says, adding a functional handle for a class method to an array causes some kind of issue with the GC. No errors are reported when compiling or executing the script, but closing the game will flood the console with various warnings and errors.

A sample script:

funcdef void FuncDef(int);

class script{
	array<FuncDef@> listeners;
	
	script(){
		// GC errors >>
		listeners.insertLast(@FuncDef(this.class_method));
		
		// No Problems with local variables >>
		FuncDef@ local = FuncDef(this.class_method);
		// No problems with global functions >>
		listeners.insertLast(global_function);
	}
	
	void class_method(int a) { puts(a + ""); }
}

void global_function(int a) { puts(a + ""); }

The errors all look like below, but instead ‘m9’ and ‘$func’ different built-in angelscript and game specific types are given. Also ref count ranges somewhere around -3 > 3.

WARN : There is an external reference to an object in module 'm9', preventing it from being deleted
ERROR: Object {4}. GC cannot destroy an object of type '$func' as it can't see all references. Current ref count is 1.
Advertisement

Thanks for bringing this up.

I'll look into this. For some reason the garbage collector is not able to identify and break the circular reference that is created from the script class→array→delegate→script class.

In the meantime you can work around this by manually breaking the circular reference before shutting down, e.g. by resizing the array to 0.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I've fixed this in rev 2667

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

@WitchLord Thanks!

This topic is closed to new replies.

Advertisement