Jump to content
  • Advertisement
Sign in to follow this  
Solokiller

Odd behavior when using globals

This topic is 520 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a script that uses globals that access eachother. In order to ensure proper order of initialization, i create the instance of the global that is accessed by other globals on demand:

namespace detail
{
CMultiScripts@ __MultiScripts = null;
}

/**
*	Gets the global multi scripts manager.
*/
CMultiScripts@ get_MultiScripts()
{
	if( detail::__MultiScripts is null )
	{
		@detail::__MultiScripts = CMultiScripts();
	}
		
	return @detail::__MultiScripts;
}

However, because i initialize it to null explicitly, the global is initialized to null after my globals have called get_MultiScripts, destroying the first instance.

If i remove the explicit assignment, everything works as expected.

 

I think this may be a bug, should the compiler remove explicit initialization to null with handles in this case?

Share this post


Link to post
Share on other sites
Advertisement

I'll investigate this.

 

I think this particular situation can probably be easily fixed the way you suggested by detecting and removing explicit initialization to null. 

 

As for guaranteeing correct order of initialization of global variables, that is a much trickier matter. To some extent the compiler already tries to reorder the initialization so that a variable that depends on another will be initialized later. However, currently when the access to the other variable is hidden with function calls the compiler is not able to see the dependency. I have on my to-do list an item to try to implement a deep scan of the produced bytecode to verify the dependencies even for these cases, but that is a rather complex implementation and it will probably take a while before I even get to start working on this.

Share this post


Link to post
Share on other sites

I've changed this in revision 2377, so that now handles explicitly initialized with null in declarations no longer produce any bytecode.

 

Regards,

Andreas

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!