• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Dentoid

Constructors/Destructors

13 posts in this topic

Hi I've made a binding between AngelScript and std::string so that std::string is used as AngelScript strings. The problem I'm having now is that if I have a script like this: void blah () { if (something) return; String blah = "Bleh!"; } Then it seems like it runs the destructor of "blah" on the return, but never the constructor, which results in destroying an unconstructed object, which means crash in my case. If I put the "String blah..." before the return (which I guess forces it to construct) it seems to work. Any idea if I'm doing something wrong, or if it's a bug? /Anders Stenberg
0

Share this post


Link to post
Share on other sites
This could actually be a bug. Would it be possible for you to pass me the code you used to register the string object. I'll use it to make some tests to see if it a bug in AngelScript or simply that you did something wrong when registering the object.
0

Share this post


Link to post
Share on other sites
I've got a couple of wrappers that look like this:

std::string StringFactory (asUINT length, const char *s)
{
return std::string (s);
}

void ConstructString (std::string *thisPointer)
{
new(thisPointer) std::string ();
}

void DestructString (std::string *thisPointer)
{
thisPointer->~string ();
}

void AssignString (std::string &other, std::string *thisPointer)
{
new(thisPointer) std::string (other);
}



And I register them like this:


engine->RegisterObjectType ("String", sizeof (std::string), asOBJ_IS_COMPLEX);
engine->RegisterStringFactory ("String", asFUNCTION(StringFactory), asCALL_CDECL | asCALL_RETURNBYREF);
engine->RegisterTypeBehaviour ("String", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ConstructString), asCALL_CDECL_OBJLAST);
engine->RegisterTypeBehaviour ("String", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(DestructString), asCALL_CDECL_OBJLAST);
engine->RegisterTypeBehaviour ("String", asBEHAVE_ASSIGNMENT, "String &f(const String&)", asFUNCTION(AssignString), asCALL_CDECL_OBJLAST);

0

Share this post


Link to post
Share on other sites
Your AssignString doesn't return anything. It should return a reference to the string, i.e. the thisPointer.

I'm not sure if this is what is causing the original problem, I'll do some tests now.

...

Ok, I've verified that it is in fact a bug. Though it is not an implementation bug, but rather a design bug thus it will take me some time to correct it. For now, you can work around it by declaring the string at the beginning of the script (as you yourself noticed).



[Edited by - WitchLord on July 30, 2004 2:01:14 PM]
0

Share this post


Link to post
Share on other sites
Quote:
Original post by WitchLord
Your AssignString doesn't return anything. It should return a reference to the string, i.e. the thisPointer.


Ooops. Interesting that it appears to work the way it is now too though. :)
0

Share this post


Link to post
Share on other sites
It's working because the returned reference isn't used, so it doesn't matter that it is not a valid string reference. If you had written a script like the following it wouldn't work:


string a, b;
a = b = "Bleh!";


I've figured out how to fix the bug, I hope that I'll be able to do so this weekend. Shouldn't be much more than an hour of work.
0

Share this post


Link to post
Share on other sites
The plot thickens...

When compiling a script like the one above the assert at as_bytecode.cpp:316 fails. "assert( n < destructors.GetLength() );"
The interesting thing is that now it only works if I put the "String blah;" _after_ the return, instead of the other way around as before.

I haven't tried to figure this out on my own. Any ideas?

Oh, and this is with 1.8.0c.

/Anders Stenberg
0

Share this post


Link to post
Share on other sites
Please download 1.8.1 WIP 3 and use that instead of 1.8.0c. There are just too many bugs in 1.8.0c.

If the bug still continues to present itself with 1.8.1 WIP 3 let me know, and I'll fix it.
0

Share this post


Link to post
Share on other sites
Oh sorry, I was wrong about my version. It was either WIP 2 or 3 I used (I'm not home right now and I won't be for another week, so I cannot check what version I had.)

I usually check angelcode out pretty much every day, and update whenever a new version comes around. If WIP 3 is very recent I might have missed that one though.
0

Share this post


Link to post
Share on other sites
Great. (Although I personally don't require anything to be done quickly, since I probably won't be working on anything angelscript related in a week or so. :)
0

Share this post


Link to post
Share on other sites
No worries. I found the problem already.

I'll release a new version with the latest changes today, or first thing tomorrow.

I did however discover that GNUC returns objects of type std::string in memory, even though the size is only 4 bytes. This doesn't follow what I had found earlier, which means that I will have to do more research to find out when and why GNUC returns objects in memory. It will probably result in yet another flag for RegisterObjectType().
0

Share this post


Link to post
Share on other sites
void AssignString (std::string &other, std::string *thisPointer)
{
new(thisPointer) std::string (other);
}

Ignoring the comment about how this should return the reference to thisPointer, I am not familiar with this syntax of new. Whats going on here?

J
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0