BlackMoons

Members
  • Content count

    424
  • Joined

  • Last visited

Community Reputation

460 Neutral

About BlackMoons

  • Rank
    Member
  1. So difficult to find 3d artists!

    So where are better places to find artists?
  2. Line numbers for non-terminated string literal?

    Awesome.  Yea its very likely none of my string literals contained ; to end a statement block, that may be why it never flagged any more errors?
  3. Line numbers for non-terminated string literal?

    No, It does not give any other errors (Unless my code is somehow obscuring them). It does not appear to detect that "Hello" is not valid syntax if it did pick up the parsing wrong.   Even in a *very* large file, it gave no errors whatsoever except for 'non-terminated string literal' on a the very last string literal of the file. that is why I thought it was so odd. I would understand if the parser puked a few lines after the non-terminated string literal, but when it complains at the very last valid literal suggests that it something is going wrong in detection.   And yea, I didn't think that Angelscript supported multi-line string literals using ", I thought that only worked with """ Hence detecting a broken " string literal should be easy, Just look for a newline in the middle of a " and you know its wrong. I thought that is what the existing code did, but for some reason it kept going after the error and reported the error on the very last string literal to be parsed.
  4. Add-ons license

    Thank you for the very liberal licensing of Angelscript. Its really refreshing to be able to use the code however is needed without worry.
  5. With the following code: string foo = " string bar = "Hello"; string bar2 = "World"; Angelscript throws a compile error of "non-terminated string literal" line 3 char 21   When it really should be throwing the error on line 1 char 14.   In much larger more complex files, it seems to always throw the error on the very last string literal regardless where it happens in the file and does not complain about anything else. Makes it kinda hard to find out what string literal you messed up on.  
  6. Is this assignment operator correct?

    Ah, So should I just register the =operator directly like this? r = scriptEngine->RegisterObjectMethod("ObjectPicker", "ObjectPicker & opAssign(const ObjectPicker &in)", asMETHOD(ObjectPicker,operator=), asCALL_THISCALL); assert( r >= 0 );
  7. Is this assignment operator correct?

    Is the following assignment operator correct? I am mainly wondering about if rhs should be released? Since its a const object I can't, Or does the fact it is passed by ref instead of handle means the ref count was not incremented?   Is it better to take the rhs by handle to avoid the copy of the object? class ObjectPicker : public ScriptRef { public: std::vector<ObjectPick> mObjects; ObjectPicker & ScriptAssign(const ObjectPicker & rhs) { mObjects = rhs.mObjects; AddRef(); // because of returning object return *this; } }; (ObjectPicker is registered as asOBJ_REF) r = scriptEngine->RegisterObjectMethod("ObjectPicker", "ObjectPicker @ opAssign(const ObjectPicker &in)", asMETHOD(ObjectPicker,ScriptAssign), asCALL_THISCALL); assert( r >= 0 );
  8. Is there a bug with function callbacks?

    "The delegates are objects" Yea I learned this one the hard way last week. Be warned that a delegate will not == another delegate that points to the same function and class unless it actually is the same delegate object. They also maintain a ref to the object.
  9. Removing a callback

    Yea, Not too sure what could make it smoother. Maybe moving asIObjectType * type = function->GetDelegateObjectType(); std::string weakRefDecl = std::string("weakref<") + type->GetName() + ">"; asIObjectType *weakRefType = engine->GetObjectTypeById(type->GetModule()->GetTypeIdByDecl(weakRefDecl.c_str())); inside the constructor of CScriptWeakRef Of course, that breaks existing code, but a new assert should at least alert people to the break. (Yea. I dislike breaking existing peoples code too so, bad idea I guess)   Another option might be some ability to set a CScriptWeakRef via function instead of just by constructor. CScriptWeakRef * foo = new CScriptWeakRef(); foo->SetRef(object,type); Of course that makes the interface a little weird as constructor and setting method no longer match in usage.     Another, cleaner option for delegates, might be to just have a new (C++ only?) class like WeakRefDelegate that has an assignment/copy operator for a asIScriptFunction* (And back again if passing back to the script engine is needed?). Ideally it would also be smart enough to handle non delegate functions transparently (Just leave the internal WeakRef set to null and set a bool to say the function can be called without a valid WeakRef)
  10. Removing a callback

    Ok updated to 2.28.2.   Now its crashing at // The given type should be the weakref template instance assert( strcmp(type->GetName(), "weakref") == 0 || strcmp(type->GetName(), "const_weakref") == 0 ); Thanks for that assert btw. So I assume I am passing the wrong type altogether. How do I get the type I want to construct a WeakRef?   <edit> Ahhhh. Found this http://www.gamedev.net/topic/647835-ownership-problem-of-funcdefs/ that also had the same problem and fixed it. Again, thanks for the assert it REALLY helped me figure this out!!! PS: GetObjectTypeByDecl still does not exist.   For anyone who was wondering or later finds this post with the same problem, the correct code was: void ObjectManager::AddPowerDraw(asIScriptFunction* function) { asIScriptEngine * engine = Engine::mScript->mScriptEngine; mPowerCallbacks.push_back(PowerCallback()); // Todo: Check for function->GetFuncType() == asFUNC_DELEGATE mPowerCallbacks.back().mFunction = function->GetDelegateFunction(); void * object = function->GetDelegateObject(); asIObjectType * type = function->GetDelegateObjectType(); std::string weakRefDecl = std::string("weakref<") + type->GetName() + ">"; asIObjectType *weakRefType = engine->GetObjectTypeById(type->GetModule()->GetTypeIdByDecl(weakRefDecl.c_str())); mPowerCallbacks.back().mRef = new CScriptWeakRef(object,weakRefType); function->Release(); }
  11. Removing a callback

    Hmmm, Run into a roadblock void ObjectManager::AddPowerDraw(asIScriptFunction* function) { mPowerCallbacks.push_back(PowerCallback()); mPowerCallbacks.back().mFunction = function->GetDelegateFunction(); void * object = function->GetDelegateObject(); asIObjectType * type = function->GetDelegateObjectType(); Engine::mScript->mScriptEngine->AddRefScriptObject(object, type); // Add ref to object, as CScriptWeakRef releases an object. mPowerCallbacks.back().mRef = new CScriptWeakRef(object,type); function->Release(); } It crashes when it calls 'mPowerCallbacks.back().mRef = new CScriptWeakRef(object,type);' Inside the constructor of CScriptWeakRef it crashes at: 'm_type->GetEngine()->ReleaseScriptObject(m_ref, m_type->GetSubType());' the crash in the ReleaseScriptObject function happens at if( objType->flags & asOBJ_REF )   Hence why I added the 'Engine::mScript->mScriptEngine->AddRefScriptObject(object, type);' line to my own code. but that does not seem to help.   Further debugging shows m_type->GetSubType() returns NULL as m_type is not a template type. What am I doing wrong in constructing the weakRef?   I think I will update Angelscript next as I seem to be using 2.27.1
  12. Removing a callback

    Oh, CScriptWeakRef has a private destructor. that is a new one for me. Guess I will be using new/Release() then.
  13. Removing a callback

    Ah thanks. Is making a new delegate object very expensive?   Hmm, Now I have the problem where my script classes destructor won't get called to free up any remaining callbacks since the callbacks hold a ref to the object. Hmmmm.   Now I have to decide between breaking up the delegate and not holding a ref to the object (potentially dangerous if a ref is not removed properly) or have a separate 'clean up' function to be called when a script object needs to be destroyed. (Technically I already have one I call from the destructor because mixins can't override the destructor, but I would rather not have to call a named function from C++ to cleanup a script class)   This does seem kind of like a task for weak references as I dislike making the scripting side more complex and would like to be able to report errors rather then crash.   Do I just (C++ side) CScriptWeakRef ref; asIScriptFunction *callback; void SetCallback(asIScriptFunction *cb) { ... callback = cb->GetDelegateFunction(); CScriptWeakRef ref(cb->GetDelegateObject(),cb->GetDelegateObjectType()); cb->Release() ... } void CallCallback() { void* object = ref.Get(); if (object == NULL) return; // Call callback with 'object' } And its all good? I know ref being a local object instead of being a pointer and using ->Release() is a bit naughty, but it should be OK as long as I never give ref back to the script engine right?
  14. Removing a callback

    PowerFunction @powerCallback; void Interact(User @ user) { if (mOwner.GetObject().mState > 0) { gObjects.RemovePowerDraw(powerCallback); mOwner.GetObject().mState = 0; } else { powerCallback = PowerFunction(this.UpdatePower); // Must pass same callback object to add and remove gObjects.AddPowerDraw(powerCallback); mOwner.GetObject().mState = 2; // Start with power off; } } Seems to have fixed it, but that seems kinda messy to have to store the callback in the object to remove it (And I add/remove callbacks elsewhere), is there any way to change my C++ code to compare the callback objects how I want?
  15. Removing a callback

    Hi. I have the following Angelscript code: class ElectricLightSource { void Interact(User @ user) { if (mOwner.GetObject().mState > 0) { gObjects.RemovePowerDraw(PowerFunction(this.UpdatePower)); mOwner.GetObject().mState = 0; } else { gObjects.AddPowerDraw(PowerFunction(this.UpdatePower)); mOwner.GetObject().mState = 2; // Start with power off; } } } And the C++ functions called are: ...     r = scriptEngine->RegisterFuncdef("void PowerFunction()"); assert( r >= 0 );     r = scriptEngine->RegisterObjectMethod("ObjectManager", "void AddPowerDraw(PowerFunction@)", asMETHOD(ObjectManager,AddPowerDraw), asCALL_THISCALL); assert( r >= 0 );     r = scriptEngine->RegisterObjectMethod("ObjectManager", "void RemovePowerDraw(PowerFunction@)", asMETHOD(ObjectManager,RemovePowerDraw), asCALL_THISCALL); assert( r >= 0 ); ... std::vector<asIScriptFunction*> mPowerCallbacks; ... void ObjectManager::AddPowerDraw(asIScriptFunction* function) { mPowerCallbacks.push_back(function); } void ObjectManager::RemovePowerDraw(asIScriptFunction* function) { std::vector<asIScriptFunction*>::iterator cur = mPowerCallbacks.begin(), end = mPowerCallbacks.end(); for (; cur != end; cur++) { if (*cur == function) { --end; if (cur != end) *cur = *end; mPowerCallbacks.pop_back(); return; } } } My problem is that the remove call, "if (*cur == function)" never passes. What am I doing wrong?