Bug: New Functions not accessibly by GetGlobalFunctionByIndex after removing different configuration group

Started by
2 comments, last by Robert42 9 years, 10 months ago

Hey smile.png

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 smile.png

Advertisement

Thanks. I'll investigate this problem and update you when I've fixed it.

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 problem in revision 1965.

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

Great! Thanks! Now The Auto Completion of my terminal is working again without problems ;)

This topic is closed to new replies.

Advertisement