Hello,
I'm getting a strange error when trying to registering a reference type.
the object:
[source lang="cpp"]class ReferenceObject
{
public:
inline void incReferenceCount() noexcept
{
++refCount;
}
inline void decReferenceCount() noexcept
{
if (--refCount == 0)
delete this;
}
private:
int refCount;
};[/source]
the registration:
[source lang="cpp"]
asIScriptEngine* engine = asCreateScriptEngine (ANGELSCRIPT_VERSION);
if (engine == nullptr)
{
}
engine->SetMessageCallback (asFUNCTION (messageCallback), 0, asCALL_CDECL);
int r = 0;
r = engine->RegisterObjectType("ReferenceObject", 0, asOBJ_REF);
r = engine->RegisterObjectBehaviour("ReferenceObject", asBEHAVE_ADDREF, "void f()", asMETHOD(ReferenceObject, incReferenceCount), asCALL_THISCALL);
r = engine->RegisterObjectBehaviour("ReferenceObject", asBEHAVE_RELEASE, "void f()", asMETHOD(ReferenceObject, decReferenceCount), asCALL_THISCALL);
[/source]
[source lang="bash"] (0, 0) : ERR : Failed in call to function 'RegisterObjectBehaviour' with 'ReferenceObject' and 'void f()'
(0, 0) : ERR : Failed in call to function 'RegisterObjectBehaviour' with 'ReferenceObject' and 'void f()'[/source]
What am I doing wrong here?
Thanks
Registering a reference type
That is a good question. What's the value of the return code for RegisterObjectBehaviour?
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
[source lang="cpp"]engine->RegisterObjectType("ReferenceObject", 0, asOBJ_REF);[/source]
result = 67108876 // This looks like a bogus number.
[source lang="cpp"]engine->RegisterObjectBehaviour("ReferenceObject", asBEHAVE_ADDREF, "void f()", asMETHOD(ReferenceObject, incReferenceCount), asCALL_THISCALL);[/source]
result = -7
[source lang="cpp"]engine->RegisterObjectBehaviour("ReferenceObject", asBEHAVE_RELEASE, "void f()", asMETHOD(ReferenceObject, decReferen
ceCount), asCALL_THISCALL);[/source]
result = -7
result = 67108876 // This looks like a bogus number.
[source lang="cpp"]engine->RegisterObjectBehaviour("ReferenceObject", asBEHAVE_ADDREF, "void f()", asMETHOD(ReferenceObject, incReferenceCount), asCALL_THISCALL);[/source]
result = -7
[source lang="cpp"]engine->RegisterObjectBehaviour("ReferenceObject", asBEHAVE_RELEASE, "void f()", asMETHOD(ReferenceObject, decReferen
ceCount), asCALL_THISCALL);[/source]
result = -7
-7 is the error code for "not supported". One possible cause is that your version of AngelScript doesn't allow the native calling convention. What platform are you using?
67108876 looks less bogus in hexadecimal, i.e. 0x400000C. This is the type id of the type that you just registered. If the value has been negative, then it would be an error, but any positive value is a successful call.
SiCrane is probably correct. The native calling conventions are probably not supported on your platform, in which case you can use the generic calling convention instead with wrappers.
For reference, the manual describes the meaning of the return codes: Manual: RegisterObjectBehaviour
Regards,
Andreas
SiCrane is probably correct. The native calling conventions are probably not supported on your platform, in which case you can use the generic calling convention instead with wrappers.
For reference, the manual describes the meaning of the return codes: Manual: RegisterObjectBehaviour
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
-7 is the error code for "not supported". One possible cause is that your version of AngelScript doesn't allow the native calling convention. What platform are you using?
Currently I'm on Mac OS X 10.7.4, but will be using this code on Win32, iOS, Android and Maybe some sort of Linux.
67108876 looks less bogus in hexadecimal, i.e. 0x400000C. This is the type id of the type that you just registered. If the value has been negative, then it would be an error, but any positive value is a successful call.
SiCrane is probably correct. The native calling conventions are probably not supported on your platform, in which case you can use the generic calling convention instead with wrappers.
For reference, the manual describes the meaning of the return codes: Manual: RegisterObjectBehaviour
Regards,
Andreas
Hmmm... this is returning true.
[source lang="cpp"]strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY")[/source]
in which case you can use the generic calling convention instead with wrappers.
[source lang="cpp"]asCALL_GENERIC[/source] returns -24
-24 is the error code for wrong calling convention. Did you actually change the functions for the generic calling convention or use the autowrap add-on?
Native calling conventions is supported on Mac. For some reason the preprocessor defines in as_config.h is not detecting your target platform properly, so the code is compiled without this support.
What is the full string returned by asGetLibraryOptions()?
What compiler are you using?
What CPU are you targetting? ppc, x86, x64?
Can you get the default preprocessor defines for your compiler? Usually the compiler has someway of outputting the defines when processing a file, some verbose logging mode.
When using the autowrappers you need to change the macros used to retrieve the function pointer for registration. asMETHOD() becomes WRAP_MFN(), asFUNCTION() becomes WRAP_FN(), etc. Just changing asCALL_THISCALL to asCALL_GENERIC without changing the macro will produce the error -24.
What is the full string returned by asGetLibraryOptions()?
What compiler are you using?
What CPU are you targetting? ppc, x86, x64?
Can you get the default preprocessor defines for your compiler? Usually the compiler has someway of outputting the defines when processing a file, some verbose logging mode.
When using the autowrappers you need to change the macros used to retrieve the function pointer for registration. asMETHOD() becomes WRAP_MFN(), asFUNCTION() becomes WRAP_FN(), etc. Just changing asCALL_THISCALL to asCALL_GENERIC without changing the macro will produce the error -24.
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 had this same problem a while back, when I tried including the Angelscript source in my project. It wouldn't work until I made sure that "i386" was a global #define. I don't know if yours is the same situation, but I thought it might help.
What is the full string returned by asGetLibraryOptions()?
"AS_MAX_PORTABILITY AS_IPHONE"
What compiler are you using?
Apple LLVM 4.0 via XCode
What CPU are you targetting? ppc, x86, x64?
i386 x86_64
Can you get the default preprocessor defines for your compiler? Usually the compiler has someway of outputting the defines when processing a file, some verbose logging mode.
-arch i386 -fmessage-length=0 -std=c++11 -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Wreturn-type -Wnon-virtual-dtor -Wno-overloaded-virtual -Wno-exit-time-destructors -Wformat -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wno-sign-compare -Wno-shorten-64-to-32 -Wno-newline-eof -Wc++11-extensions -D_DEBUG=1 -DDEBUG=1 -DJUCER_XCODE_MAC_F6D2F4CF=1 -fasm-blocks -Wdeprecated-declarations -Winvalid-offsetof -g -fvisibility=hidden -fvisibility-inlines-hidden -Wno-sign-conversion -iquote
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement