# Assertion hit

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

## Recommended Posts

Hi there and congrats on AngelScript. Very nice work :) I 've been evaluating it the last couple of days and, although doumentation is lacking, I was able to add it in my project and actually get it working (yay!). But I 'm having a problem now, that I don't seem to be able to solve by myself. I have bound this member function at some point:
GuiButton* Gui::AddButton(const std::string& text, const Vector2& pos, const Vector2& size);
// bound using:
engine->RegisterObjectMethod("Gui", "GuiButton& AddButton(const string& in, const Vector2& in, const Vector2& in)", asMETHOD(Gui, AddButton), asCALL_THISCALL);
// called from script:
GuiButton@ btn = GUI.AddButton("Hello world 3!", Vector2(200, 50), Vector2(100, 50));


[EDIT] I forgot to tell you what this function is doing :p When called, it creates a GuiButton object on the heap, adds it in an internal list and returns it as a result. Pretty basic. [/EDIT] If I run the script like this (i.e. asking for a GuiButton handle), I get this assertion:
/as_compiler.cpp:342: void asCCompiler::CompileStatementBlock(asCScriptNode*, bool, bool*, asCByteCode*): Assertion tempVariables.GetLength() == 0' failed.
1) Is this my mistake? 2) Any way to make it work? Thanks a lot for any help :)

##### Share on other sites
This is a mistake of mine. That assert is there to verify that this never happens, since it happened there is a bug in the library that I need to find.

I'm not sure but you may be able to work around this by returning a GuiButton@ instead of a reference.

You can do this by registering your function like so:

engine->RegisterObjectMethod("Gui", "GuiButton@+ AddButton(const string& in, const Vector2& in, const Vector2& in)", asMETHOD(Gui, AddButton), asCALL_THISCALL);

The library will automatically increase the reference count for the returned object (because of the autohandle @+), so you don't have to change your C++ function.

Give it a try and let me know if it works. In the meantime I'll work on the true solution to the problem.

Regards,
Andreas

##### Share on other sites
Quote:
 Original post by WitchLordI'm not sure but you may be able to work around this by returning a GuiButton@ instead of a reference.You can do this by registering your function like so:engine->RegisterObjectMethod("Gui", "GuiButton@+ AddButton(const string& in, const Vector2& in, const Vector2& in)", asMETHOD(Gui, AddButton), asCALL_THISCALL);The library will automatically increase the reference count for the returned object (because of the autohandle @+), so you don't have to change your C++ function.

Yay! This works!
Gee, where are those things documented? I had never seen before this construct "@+"...

Thanks a lot for the quick response Andreas :D

##### Share on other sites
The @+ was mentioned on the forum and I believe is in the list of changes in changelog.

##### Share on other sites
This forum -is- the documentation.

##### Share on other sites
Quote:
 Original post by DeyjaThis forum -is- the documentation.

Yes, I think I got it ;)
Although a place to share knowledge (which doesn't expire, like forum posts) might be nice (wiki, anyone :p).

I am an open source developer myself and I can perfectly understand that documentation is not top-priority for an open-source developer (although it should be). But if we, the users, could put our little hints & tips - knowledge gained either searching or asking here - somewhere to stay, then it 'd be easier for a newcomer to get to know AngelScript and *stick* with it.

For example, here's a small tip for those who tried binding a const function and failed:
(by const I mean: 'void foo::bar() const')

#define asMETHODCONST(c,m) asSMethodPtr<sizeof(void  c::*)()const)>::Convert((void (c::*)()const)(&c::m))#define asMETHODCONSTPR(c,m,p,r) asSMethodPtr<sizeof(void  c::*)()const)>::Convert((r (c::*)p const)(&c::m)) 

Put these definitions somewhere globally in your sources (or even angelscript.h) and use asMETHODCONST/asMETHODCONSTPR instead of asMETHOD/asMETHODPR when binding const functions.
It's definetely not the best - or secure - way (this would be Andreas' job ;) ), but it helped me bind my Vector2 class without problems.

Regards,
Yiannis :)

##### Share on other sites
It's also possible to change code like this.

GuiButton btn = GUI.AddButton("Hello world 3!", Vector2(200, 50), Vector2(100, 50));

to

GuiButton btn;
btn = GUI.AddButton("Hello world 3!", Vector2(200, 50), Vector2(100, 50));

This works like workaround to.

##### Share on other sites
Although I got it working, many thanks wolfeinstein :)

##### Share on other sites
A Wiki would be a good idea (I believe it was brought up before as well). Unfortunately I can't put one up on my site very easily since I do not control what is installed on the server. I'll have to talk to GameDev.net staff, to see if they can install some software that I can use as a Wiki. It would of course be possible to write one in ASP, but I really don't feel like starting that project.

I try to at least keep the documentation up to date, but I can honestly say that developing the library is much more important to me. But if you feel that there is information missing in the documentation (or something wrong) then you are free to submit suggestions for improvement.

The const methods can be registered with the current asMETHODPR macro. The const would then be part of the parameter declaration. Example:

asMETHODPR(Foo, bar, () const, void)

But to simplify things I just might add a couple of macros for const methods.

##### Share on other sites
Quote:
 Original post by WitchLordThe const methods can be registered with the current asMETHODPR macro. The const would then be part of the parameter declaration. Example:asMETHODPR(Foo, bar, () const, void)`But to simplify things I just might add a couple of macros for const methods.

I *believe* I tried that but then again I might be wrong.
(Hmm, looking at the code this *should* work so probably I was mistaken)

Regards,
Yiannis.

1. 1
Rutin
23
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 28
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631738
• Total Posts
3001951
×