Hey
I found a bug. When I
- create a Configuration group
- register more than one function
- remove the configuration group
- add multiple functions not within any configuration group
one ore more of the new functions can't be accessed using GetGlobalFunctionByIndex, instead null is returned. Even for valid indices.
Here's my repro case. The reprocase prints the name of the functions, it couldn't find.
#include <angelscript.h>
#include <sstream>
#include <assert.h>
#include <iostream>
#define nullptr 0
// By setting this macro to 0, the bugs gets not reproducable anymore
#define CREATE_AND_REMOVE_GROUP 1
asIScriptEngine* as_engine = nullptr;
void dummy(){}
void checkForNullptr();
void checkScriptFunction(const std::string& functionName);
int main()
{
int r;
const char* configGroupName = "MyConfig";
as_engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
assert(as_engine != nullptr);
// register 3 script functions a(), b() and c()
r = as_engine->RegisterGlobalFunction("void a()", asFUNCTION(dummy), asCALL_CDECL); assert(r>=0);
r = as_engine->RegisterGlobalFunction("void b()", asFUNCTION(dummy), asCALL_CDECL); assert(r>=0);
r = as_engine->RegisterGlobalFunction("void c()", asFUNCTION(dummy), asCALL_CDECL); assert(r>=0);
// the checkScriptFunction checks, whether it could find the function by index and declaration
// if the function couldn't be found, a message gets printed to cerr
checkScriptFunction("a");
checkScriptFunction("b");
checkScriptFunction("c");
#if CREATE_AND_REMOVE_GROUP
r = as_engine->BeginConfigGroup(configGroupName); assert(r>=0);
r = as_engine->RegisterGlobalFunction("void x()", asFUNCTION(dummy), asCALL_CDECL); assert(r>=0);
r = as_engine->RegisterGlobalFunction("void y()", asFUNCTION(dummy), asCALL_CDECL); assert(r>=0);
r = as_engine->EndConfigGroup(); assert(r>=0);
r = as_engine->RemoveConfigGroup(configGroupName); assert(r>=0);
#endif
r = as_engine->RegisterGlobalFunction("void d()", asFUNCTION(dummy), asCALL_CDECL); assert(r>=0);
r = as_engine->RegisterGlobalFunction("void e()", asFUNCTION(dummy), asCALL_CDECL); assert(r>=0);
r = as_engine->RegisterGlobalFunction("void f()", asFUNCTION(dummy), asCALL_CDECL); assert(r>=0);
checkScriptFunction("a");
checkScriptFunction("b");
checkScriptFunction("c");
checkScriptFunction("d");
checkScriptFunction("e");
checkScriptFunction("f");
// checkForNullptr checks, whether GetGlobalFunctionByIndex returns null for a valid index
checkForNullptr();
r = as_engine->Release();
assert(r>=0);
}
void checkScriptFunctionByIndex(const std::string& functionName);
void checkScriptFunctionByDeclaration(const std::string& functionName);
void checkForNullptr()
{
size_t count = as_engine->GetGlobalFunctionCount();
for(size_t i=0; i<count; ++i)
{
asIScriptFunction* f = as_engine->GetGlobalFunctionByIndex(i);
if(f==nullptr)
{
std::cerr << "nullptr found" << std::endl;
continue;
}
}
}
void checkScriptFunction(const std::string& functionName)
{
checkScriptFunctionByIndex(functionName);
checkScriptFunctionByDeclaration(functionName);
}
void checkScriptFunctionByIndex(const std::string& functionName)
{
bool found = false;
size_t count = as_engine->GetGlobalFunctionCount();
for(size_t i=0; i<count; ++i)
{
asIScriptFunction* f = as_engine->GetGlobalFunctionByIndex(i);
if(f==nullptr)
continue;
if(f->GetName()==functionName)
{
found = true;
break;
}
}
if(!found)
std::cerr << "Couldn't find "<<functionName<<" by index" << std::endl;
}
void checkScriptFunctionByDeclaration(const std::string& functionName)
{
if(nullptr == as_engine->GetGlobalFunctionByDecl(("void "+functionName+"()").c_str()))
std::cerr << "Couldn't find "<<functionName<<" by declaration" << std::endl;
}
Thanks in Advance