Assert when casting void return value to an object handle

Started by
7 comments, last by AgentC 10 years, 5 months ago

Hi,

in the Urho3D engine we saw the following assert trigger when in script, the return value of a void function was mistakenly attempted to be cast into an object handle:


    asASSERT(ctx->type.dataType.IsReference());

in as_compiler.cpp, function asCCompiler::ConvertToVariable(asSExprContext *ctx), around line 10974.

To fix, I added the following check for void to asCCompiler::CompileConversion(asCScriptNode *node, asSExprContext *ctx) around line 8150:


    bool conversionOK = false;

    if( !expr.type.isConstant && expr.type.dataType.GetTokenType() != ttVoid )

which may not be the best way to fix, but seemed to work.

Advertisement

Can you identify what script caused the assert failure? Without having the script it is difficult to know for sure if the cause is really where you made the code changes.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Here is a statcktrace if it helps.


Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib         0x98224952 __pthread_kill + 10
1   libsystem_pthread.dylib        0x99417167 pthread_kill + 101
2   libsystem_c.dylib              0x97a59340 abort + 155
3   libsystem_c.dylib              0x97a2443e __assert_rtn + 347
4   Urho3D                         0x005735b7 asCCompiler::ConvertToVariable(asSExprContext*) + 1479 (as_compiler.cpp:10973)
5   Urho3D                         0x00573bb6 asCCompiler::ConvertToTempVariable(asSExprContext*) + 182 (as_compiler.cpp:10903)
6   Urho3D                         0x005a7f0c asCCompiler::CompileConversion(asCScriptNode*, asSExprContext*) + 2892 (as_compiler.cpp:8154)
7   Urho3D                         0x005973d1 asCCompiler::CompileExpressionValue(asCScriptNode*, asSExprContext*) + 5985 (as_compiler.cpp:7774)
8   Urho3D                         0x00595a4a asCCompiler::CompileExpressionTerm(asCScriptNode*, asSExprContext*) + 282 (as_compiler.cpp:7083)
9   Urho3D                         0x00595422 asCCompiler::CompilePostFixExpression(asCArray<asCScriptNode*>*, asSExprContext*) + 658 (as_compiler.cpp:7031)
10  Urho3D                         0x0057890b asCCompiler::CompileExpression(asCScriptNode*, asSExprContext*) + 731 (as_compiler.cpp:7007)
11  Urho3D                         0x00594ec0 asCCompiler::CompileCondition(asCScriptNode*, asSExprContext*) + 5984 (as_compiler.cpp:6962)
12  Urho3D                         0x005775ab asCCompiler::CompileAssignment(asCScriptNode*, asSExprContext*) + 571 (as_compiler.cpp:6753)
13  Urho3D                         0x00569324 asCCompiler::CompileInitialization(asCScriptNode*, asCByteCode*, asCDataType&, asCScriptNode*, int, unsigned long long*, int) + 4420 (as_compiler.cpp:2280)
14  Urho3D                         0x0056edd2 asCCompiler::CompileDeclaration(asCScriptNode*, asCByteCode*) + 2034 (as_compiler.cpp:2105)
15  Urho3D                         0x0056b118 asCCompiler::CompileStatementBlock(asCScriptNode*, bool, bool*, asCByteCode*) + 504 (as_compiler.cpp:1027)
16  Urho3D                         0x0056a2e2 asCCompiler::CompileFunction(asCBuilder*, asCScriptCode*, asCArray<asCString>&, asCScriptNode*, asCScriptFunction*, sClassDeclaration*) + 514 (as_compiler.cpp:552)
17  Urho3D                         0x0053e769 asCBuilder::CompileFunctions() + 889 (as_builder.cpp:720)
18  Urho3D                         0x005383f5 asCBuilder::Build() + 101 (as_builder.cpp:242)
19  Urho3D                         0x005ce09a asCModule::Build() + 266 (as_module.cpp:233)
20  Urho3D                         0x003dd838 Urho3D::ScriptFile::Load(Urho3D::Deserializer&) + 1176 (ScriptFile.cpp:152)
21  Urho3D                         0x0026458b Urho3D::ResourceCache::GetResource(Urho3D::ShortStringHash, Urho3D::StringHash) + 1419 (ResourceCache.cpp:434)
22  Urho3D                         0x00263fa4 Urho3D::ResourceCache::GetResource(Urho3D::ShortStringHash, Urho3D::String const&) + 148 (ResourceCache.cpp:393)
23  Urho3D                         0x000691b1 Urho3D::ScriptFile* Urho3D::ResourceCache::GetResource<Urho3D::ScriptFile>(Urho3D::String const&) + 81 (ResourceCache.h:176)
24  Urho3D                         0x00068332 Urho::Start() + 146 (Urho3D.cpp:148)
25  Urho3D                         0x00098b3f Urho3D::Application::Run() + 351 (Application.cpp:64)
26  Urho3D                         0x00067e9b RunApplication() + 187 (Urho3D.cpp:72)
27  Urho3D                         0x00067fb3 main + 51 (Urho3D.cpp:72)
28  libdyld.dylib                  0x93ee470d start + 1

The script was of the following type:

void CreateComponent(const String&in componentName)

{

... // What happens here should not be relevant

}

and somewhere in a main function the following would trigger the assert when compiling (ParticleEmitter is a registered C++ reference type)

ParticleEmitter@ em = cast<ParticleEmitter>(CreateComponent("ParticleEmitter"));

That's of course total nonsense :)

It helps somewhat but not enough. smile.png

I can see that the problem happens while compiling the initialization of a local variable during the declaration and the initialization expression has an explicit type conversion.

The asCCompiler has a member outFunc. Can you check the content of that member to determine which script function is being compiled when the assert fails, and then post the script for that function so I can add a test case for this problem in my regression test suite?

[edit] Never mind. AgentC posted it while I was typing. :)

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 is my first time posting on your board and i always wanted to say thanks for angelscript! <3 <3 <3

I've checked in the fix in revision 1763.

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

@ChrisMAN. You're most welcome! :D

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Thanks! I'll take in the official fix.

This topic is closed to new replies.

Advertisement