Config Group Question

Started by
6 comments, last by DaesDemon 18 years, 6 months ago
Hello again Angel friends I am trying to use the ConfigGroup to allow the reuse of a variable name "control" with different type. I am in front of a problem that is when i try to remove the config group declaring this variable, i get the error code CONFIG_GROUP_ALREADY_IN_USE. I use it like this:

engine->beginConfigGroup("Group");
engine->RegisterGlobalProperty("IntControl control",&myIntControl);
engine->endConfigGroup();
engine->executeString("control.doSomethingToInt()");
engine->removeConfigGroup("Group");
// AND LATER
engine->beginConfigGroup("Group");
engine->RegisterGlobalProperty("BoolControl control",&myBoolControl);
engine->endConfigGroup();
engine->executeString("control.doSomethingToBool()");
engine->removeConfigGroup("Group");



I guess that AS keep the compiled code but how can i manage that? Thanks for help.
Advertisement
I'm sure that you receive an error message when calling RemoveConfigGroup(), stating that the group is in use. You'll have to make sure that all script code and any variables depending on the config group is removed first.

You can discard the script code by calling Discard() for the module. If that isn't sufficient, you may also want to call GarbageCollect() to remove variables that are no longer used.

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

Yes i get the error in removing the group.
So I tried as you said to add
engine->Discard(NULL); // as i execute in NULL Module
engine->GarbageCollect(true); // with and without this line
after each call of my executeString(NULL,cmd) Function.

And now i get a crash on the second redeclaration of the global Var (after the removing and recreating of the group)
in RegisterGlobalProperty on this part:
	// Update all pointers to global objects,	// because they change when the array is resized	for( asUINT n = 0; n < globalProps.GetLength(); n++ )	{		if( globalProps[n]->type.IsObject() && !globalProps[n]->type.IsReference() && !type.IsObjectHandle() )		{			int idx = -globalProps[n]->index - 1;			void **pp = &globalPropAddresses[idx-1];			globalPropAddresses[idx] = (void*)pp;		}	}
when the isObject() function is called.
When i remove the Discard it don't crash but the var is sometime not redeclared as i explain before.

I put here my log if it can be of any use:
18:27:20: AngelScript: Register class SceneManager18:27:20: AngelScript: Register SceneManager::void f()18:27:20: AngelScript: Register SceneManager::void f()18:27:20: AngelScript: Register SceneManager::void showBoundingBoxes(bool show)18:27:20: AngelScript: Register SceneManager::bool getShowBoundingBoxes()18:27:20: AngelScript: Register SceneManager::void setDisplaySceneNodes(bool display)18:27:20: AngelScript: Register SceneManager::void setShowDebugShadows(bool show)18:27:20: AngelScript: Register SceneManager::bool getShowDebugShadows()18:27:20: AngelScript: Register class Log18:27:20: AngelScript: Register Log::void logMessage(const string &in message,int e,bool b)18:27:20: AngelScript: Register class Editor18:27:20: AngelScript: Register Editor::SceneManager getSceneManager()18:27:20: AngelScript: Register class Panel18:27:20: AngelScript: Register class ControlBool18:27:20: AngelScript: Register ControlBool::void setValue(bool value)18:27:20: AngelScript: Register ControlBool::bool getValue()18:27:20: AngelScript: Register class ControlInt18:27:20: AngelScript: Register ControlInt::void setValue(int value)18:27:20: AngelScript: Register ControlInt::int getValue()18:27:20: AngelScript: Register class PanelObjectList18:27:20: AngelScript: Register PanelObjectList::void lightPopulate(SceneManager@ sceneManager)18:27:20: AngelScript: Register global Log log = 0x68a64d018:27:20: AngelScript: Register global Editor editor = 0x68a53a818:27:22: PanelClient::OnChildResized()18:27:22: PanelClient::OnChildResized()18:27:22: PanelClient::OnChildResized()18:27:22: PanelClient::OnChildResized()18:27:22: AngelScript: BeginConfigGroup(Group01)18:27:22: AngelScript: Register global Panel panel = 0xddab03818:27:22: AngelScript: Register global SceneManager sceneMgr = 0xdd8e4d018:27:22: AngelScript: Register global PanelObjectList control = 0xa2e45c018:27:22: AngelScript: EndConfigGroup()18:27:22: AngelScript: Exec->control.lightPopulate(sceneMgr)18:27:22: Populate is occurring , that is a hourra18:27:22: AngelScript: Execution Success18:27:22: AngelScript: RemoveConfigGroup(Group01)18:27:22: PanelFactoryComposant::manageParentDisplay18:27:22: PanelFactoryComposant::manageParentDisplay18:27:22: PanelFactoryComposant::manageParentDisplay18:27:22: PanelFactoryComposant::manageParentDisplay18:27:29: AngelScript: BeginConfigGroup(Group01)18:27:49: AngelScript: Register global Panel panel = 0xddab038


As you can see in the log i register exactly the same Var Panel (with same pointer) because the two control are on the same panel.

I am stuck :(

Should i use the SetConfigGroupModuleAccess function or is the config group accessible by default?
PS: Humm i see that in the doc so it should goes well, isn't it?
Quote:
The default module access is granted.


[Edited by - DaesDemon on September 30, 2005 12:34:30 PM]
It looks like a bug in AngelScript. I'll look into this as soon as possible.

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

Thanks you very much WitchLord.
I will post back if i find something on my side.

I had a dive in AngelScript Code to see what could goes wrong and find that:
void asCConfigGroup::RemoveConfiguration(asCScriptEngine *engine){	assert( refCount == 0 );	asUINT n;	// Remove global variables	for( n = 0; n < globalProps.GetLength(); n++ )	{		for( asUINT m = 0; m < engine->globalProps.GetLength(); m++ )		{			if( engine->globalProps[m] == globalProps[n] )			{				delete engine->globalProps[m];				engine->globalProps[m] = 0;			}		}	}

So you delete the globalProp in the engine that is the same that the globalProp in the configGroup.
Perhaps i am wrong but when you delete the engine globalProps, shouldn't you change the lenght var for the asCArray globalProps and put the last element in place of the deleted one.
Because i cannot see in the code the update of the lenght anywhere.
And apparently what happens in my case is:
Register Prop[0]
Register Prop[1]
Begin ConfigGroup
Register Prop[2]
End ConfigGroup
Remove Group ( Prop[2] =0 )
Register Prop[3] There it should perhaps register Prop[2] again because it was removed.
( and crash when update all pointers because it do that:
*Prop[0]->type.IsObject()
*Prop[1]->type.IsObject()
*Prop[2]->type.IsObject Crash because NULL pointer

It seems to be the same for systemFunctions... and the other asArray.

Hope that helps.
Regards.
DaesDemon
You may very well be correct about this.

This is obviously a scenario that wasn't tested when I implemented the configuration groups. I'll add some new test cases to cover these scenarios and make sure that they are all working.

Thanks for taking the time to figure out what's going wrong.

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

My pleasure to contribute ;)

This topic is closed to new replies.

Advertisement