Problem with passing string objects
I have a function
void S_SetObjectMaterial(int id, asCScriptString &matName);
which I register using
rval = se->RegisterGlobalFunction("void SetObjectMaterial(int id, string &matName);", asFUNCTION(S_SetObjectMaterial), asCALL_CDECL);
The problem is that when I call this function from inside a script and pass 0 as the integer argument, I get an exception inside angelscript in the opcode BC_CHKREF. Digging into angelscript a bit I find that I have a stack with the integer argument at l_sp + 0x0 followed by a pointer to the string object at l_sp + 0x4. The opcode before BC_CHKREF is BC_GETOBJREF, which copies the pointer onto the stack on top of some existing value. BC_CHKREF always checks l_sp + 0x0 for a null value, instead of the pointer at l_sp + 0x4, so it fails when the integer argument is 0.
Am I doing something wrong? I just commented out the BC_CHKREF check for now. This is with recent code from the SVN.
Thanks!
edit-
Here's the listing for that statement:
- 28,2 -
57 4 * SUSPEND
58 4 * STR 5 (l:7 s:"penguin")
59 6 * CALLSYS 28 (string@ ?(const int, const uint8&))
61 4 * STOREOBJ v1
62 4 * PSF v1
63 5 * CHKREF
64 5 * POP 1
65 4 * VAR v1
66 5 * PshV4 v0
67 6 * GETOBJREF 1
68 6 * CHKREF
69 6 * CALLSYS 85 (void SetObjectMaterial(int, string&inout))
71 4 * PSF v1
72 5 * FREE 0x282d890
Interesting, the checkref is indeed placed incorrectly by the AngelScript compiler. I'll have to look into this. Thanks for the report.
Update: I've reproduced the problem. It shouldn't be long before I have a fix ready.
Regards,
Andreas
[Edited by - WitchLord on June 24, 2007 8:08:56 AM]
Update: I've reproduced the problem. It shouldn't be long before I have a fix ready.
Regards,
Andreas
[Edited by - WitchLord on June 24, 2007 8:08:56 AM]
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
The bug should be fixed now. You can get the solution from the SVN, revision 160.
Thanks,
Andreas
Thanks,
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
Ok, thanks!
But there's a new problem, this time with BC_ChkNullS:
as_context.cpp line 2840
size_t *a = (asDWORD*)*(size_t*)(l_sp + WORDARG0(l_bc));
should be
size_t *a = (size_t*)(l_sp + WORDARG0(l_bc));
It is checking the first bytes of the object rather than the pointer to the object.
But there's a new problem, this time with BC_ChkNullS:
as_context.cpp line 2840
size_t *a = (asDWORD*)*(size_t*)(l_sp + WORDARG0(l_bc));
should be
size_t *a = (size_t*)(l_sp + WORDARG0(l_bc));
It is checking the first bytes of the object rather than the pointer to the object.
I get a compile error like this as well. Using latest SVN rev 160 with MSVC++ 6.
d:\visual c++\as\sdk\angelscript\source\as_context.cpp(2840) : error C2440: 'initializing' : cannot convert from 'unsigned long *' to 'unsigned int *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Same error in Dev-C++.
d:\visual c++\as\sdk\angelscript\source\as_context.cpp(2840) : error C2440: 'initializing' : cannot convert from 'unsigned long *' to 'unsigned int *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Same error in Dev-C++.
CyberGorgolith: You're right. That was sloppy of me. I must have been tired yesterday. I'll correct it a.s.a.p.
Blednik: I'll have a look at the compiler error as well. Thanks.
Blednik: I'll have a look at the compiler error as well. Thanks.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
It should be working now. I've fixed some other bugs as well (unrelated to this) so you can get the latest revision from SVN (163).
Thanks for the help.
Regards,
Andreas
Thanks for the help.
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement