Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Everything posted by Myran

  1. I use a slightly older version of the library (2.30.2), so this might have been changed, but in this version there is no null check when using the indexing operator,   So this throws a null pointer exception: array<int>@ arr = null; arr.length(); But this does not: array<int>@ arr = null; arr[0];
  2. Myran

    Reference type memory leak?

    So I have a reference type where i register the asBEHAVE_ADDREF and asBEHAVE_RELEASE behaviours, and I construct this reference type in C++. So in AngelScript I have a C++ method that returns this reference type, but if I never assign the returned value to anything the reference behaviours are never called so the object never gets deleted. Is there something I can do to detect this or have I done something wrong?     So basically this leaks memory: sound.Play2D();   and this does not: SoundInstance@ si = sound.Play2D();
  3. Myran

    Reference type memory leak?

    Ah alright, I changed it to return a handle and I incremented the ref count, so now it works. Thank you.
  4. Myran

    Crash in AddRefScriptObject

    Aha, thank you. That makes a lot of sense.
  5. Myran

    Crash in AddRefScriptObject

    I want to be able to instantiate different classes based on a string, to do that I use this C++ function: void InstantiateClass(asIScriptGeneric *gen) { auto name = (std::string*)gen->GetArgObject(0); auto params = (SValue*)gen->GetArgAddress(1); auto mod = gen->GetEngine()->GetModule("Scripts"); auto type = mod->GetObjectTypeByName(name->c_str()); if (!type) { printf("%s '%s'\n", "Couldn't find class", name->c_str()); auto ret = CScriptHandle(); *(CScriptHandle*)gen->GetAddressOfReturnLocation() = ret; return; } auto tName = std::string(type->GetName()); auto factory = type->GetFactoryByDecl((tName + "@ " + tName + "(SValue& params)").c_str()); if (!factory) { printf("%s '%s' %s\n", "Couldn't find class", name->c_str(), "factory function"); auto ret = CScriptHandle(); *(CScriptHandle*)gen->GetAddressOfReturnLocation() = ret; return; } auto ctx = gen->GetEngine()->CreateContext(); ScriptEngine::PrepareContext(ctx, factory); int r = ctx->SetArgObject(0, params); assert(r >= 0); ScriptEngine::VerifyScriptExecution(ctx, ctx->Execute()); auto bObj = *((asIScriptObject**)ctx->GetAddressOfReturnValue()); ScriptEngine::UnprepareContext(ctx); auto ret = CScriptHandle(bObj, type); ctx->Release(); *(CScriptHandle*)gen->GetAddressOfReturnLocation() = ret; } This has worked well for me for a while now, but now I'm getting a crash when trying to use it on some really simple classes. It seems like when the CScriptHandle does engine->AddRefScriptObject it will crash if the class doesn't contain an object handle.   So doing it on this class works: class Explode : IAction { IAction@ dummy; Explode(SValue& params) { } bool DoAction(Actor@ owner, vec2 pos, vec2 dir) { return true; } void Update(int dt, int cooldown) { } } But if I remove IAction@ dummy, I get a crash in "void asCScriptEngine::CallObjectMethod(void *obj, asSSystemFunctionInterface *i, asCScriptFunction *s) const".
  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!