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

Assertion in garbage collector fails with array of asOBJ_REF

3 posts in this topic

I am making an RTS game where the script can get an array of units from the application, and select one of them as a target to shoot at.

The function to do this is registered like:

se->RegisterObjectMethod("Entity", "Entity@[]@ getAttackableEnemies()", asMETHOD(Entity,getAttackableEnemies), asCALL_THISCALL);

... and this is implemented by filling a CScriptArray of the type given by:

se->GetTypeIdByDecl("array<Entity@>") 

... and the script uses it like this:

Entity@[] enemies = getAttackableEnemies();

The class itself is registered like:

se->RegisterObjectType("Entity", 0, asOBJ_REF);
se->RegisterObjectBehaviour("Entity", asBEHAVE_ADDREF, "void f()", asMETHOD(Entity,AddRef), asCALL_THISCALL);
se->RegisterObjectBehaviour("Entity", asBEHAVE_RELEASE, "void f()", asMETHOD(Entity,Release), asCALL_THISCALL);

The AddRef and Release functions do nothing.

 

I have been using this on 64-bit Linux for many weeks with no problems, but now on every other platform that I'm trying to port it to (lin32, win32, mac64) it crashes with the failed assertion:

 

as_gc.cpp:273: void asCGarbageCollector::GetStatistics(asUINT*, asUINT*, asUINT*, asUINT*, asUINT*) const: Assertion `numAdded == gcNewObjects.GetLength() + gcOldObjects.GetLength() + numDestroyed' failed

 

I have also floundered around trying various other combinations such as registering the function signature as Entity@[]&, or making the script use Entity@[]@ with not much improvement. This is all very similar to a question I asked a while ago here, but obviously I did not completely understand the reason for the solution then, so I am sheepishly returning here again....

http://www.gamedev.net/topic/643542-gc-cannot-free-an-object-of-type-array-it-is-kept-alive-by-the-application

 

In that previous question, the object type was a wrapper for the real C++ class, and was registered with asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS and the script was allowed to instantiate it. I guess I could rewrite everything to do it that way again, but I was wondering if there is something I'm missing with this function registration that would let the script have a direct handle on the C++ class.

0

Share this post


Link to post
Share on other sites

An assert failure within the AngelScript library usually means a bug in the library rather than something you did wrong. Only in rare cases isn't AngelScript able to detect an incorrect usage so a proper error can be reported to the application. Incorrect registration of the interface is one of them, but what you've shown appears to be correct, so at this moment I think it is more likely to be a bug in AngelScript itself.

 

In your scenario the garbage collector somehow has an inconsistency in that it lost track of how many objects has been added to it and how many has been destroyed.

 

You say the crash happens on every platform except Linux64. Is assert not happening on Linux64 because you've compiled the library in release mode (i.e. the assert call is removed during the compilation)?

 

Is it the crash easily reproducible? Can you send me example code that reproduces the problem so that I can debug it?

 

What version of AngelScript are you currently using? In version 2.27.0 I added the method GetObjectInGC() to the asIScriptEngine interface. Perhaps by using that to iterate of the objects that is in the GC at different stages of your application you'll be able to figure out in what situation the assert failure occurs.

0

Share this post


Link to post
Share on other sites

oh... it's apology time again. I don't know why I didn't think of it before (amazing how a nights sleep makes your brain work properly again), but I had two threads touching the same script engine, without appropriate guards to prevent concurrency problems. I think the memory of that earlier thread just clouded my mind and made me jump to conclusions. Sorry for the bother!

 

As for why it did not occur on lin64, each lib was compiled using the cmake file with no options given, but my lin64 machine has substantially better hardware specs than the others. I guess when threading issues come into the picture, this could be relevant. Thanks again for the help!

0

Share this post


Link to post
Share on other sites

Can you tell me a bit more about how your two scripts were accessing the same script engine?

 

Though you probably should have your own guards in place to avoid two scripts updating the same data in the application, the script engine should have been able to protect its internal data against simultaneous access. Obviously there is a flaw somewhere in the garbage collector that allowed the two threads to mess up the internal data.

 

I'll need to find and fix this flaw, and any additional information you can provide will help.

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