Jump to content
  • Advertisement
Sign in to follow this  

Assert when casting void return value to an object handle

This topic is 2181 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


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:


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.

Share this post

Link to post
Share on other sites

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.

Share this post

Link to post
Share on other sites

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

Share this post

Link to post
Share on other sites

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 :)

Share this post

Link to post
Share on other sites

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. :)

Edited by Andreas Jonsson

Share this post

Link to post
Share on other sites

this is my first time posting on your board and i always wanted to say thanks for angelscript! <3 <3 <3

Edited by ChrisMAN

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • 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!