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

Crash on reference obj method call OSX x64

3 posts in this topic

It has been my default assumption that I may have done something wrong.  After a few days of looking into the issue I came at an impass that might need info from people who are more familiar.

 

The issue is failrly simple.  I have a registered reference type, which in the script I am calling a method on.  In c++ the code asserts as the pointer of the object is not correct.  Below is the information I've gathered about the crash.

 

System: Mac Os X 10.8.2

IDE: Xcode 4

Achritecture: 64-bit

Compiler: Apple LLVM 4.2 (default) also occurs with (LLVM GCC 4.2)

Config: Appears in both Debug and Release builds

AngelScript: 2.26.1

 

- The issue appears to be related to functions which return a specific registered value type (Vector)

- Other method calls on the same object works fine

- Multiple object types suffer from this crash

- Occurs with both direct method calls and method wrapper functions

- The pointer to the object stored in angelcode is correct

- I have also tracked the object pointer up until the assebly code in x64_CallFunction code, and it appears to be fine until then

- The same codebase works fine on Windows VS2010.  I'm currenting porting the code to OSX.

- I've attempted to re-create the issue with a new class value type and new methods, but those work fine.

- Issues also occurs if I use the "LLVM GCC 4.2" compiler

 

For reference, example configuration of the classes in question. (not full config)  Again, this code works fine on the Windows side so I think the issue is deeper.

 

//This is the suspect value type
ret = engine->RegisterObjectType("Vector", sizeof(GtVector), asOBJ_VALUE | asOBJ_APP_CLASS_CDAK); assert( ret >= 0 );

//Example of object method that fails
ret = engine->RegisterObjectType("Entity", 0, asOBJ_REF); assert( ret >= 0 );
ret = engine->RegisterObjectMethod("Entity", "Vector getOrigin()", asMETHOD(Entity, getOrigin), asCALL_THISCALL); assert( ret >= 0 );

//Another example of object method that fails
ret = engine->RegisterObjectType("Level", 0, asOBJ_REF | asOBJ_NOCOUNT); assert( ret >= 0 );
ret = engine->RegisterObjectMethod("Level", "Vector getBlockOrigin(const Vector& in)", asFUNCTION(_Level_getBlockOrigin), asCALL_CDECL_OBJFIRST); assert( ret >= 0 );

//Example of code that will break
Entity@ entity = CreateEntity("test");  //Works
entity.setOrigin(Vector(1,1,1));  //Works
Vector vector = entity.getOrigin(); //Fails: Entity::getOrigin() is called, but obj pointer is not right

 

At this point I believe the issue may deal with my compile configurations and/or the as_callfunc_x64_gcc.cpp.  I'm not versed well in assembler however, so I'm kind of stuck on what to do.  Any information anyone might be able to provide is welcomed.  If there is more information I can provide about my issue please let me know.

Edited by BirdiePeep
0

Share this post


Link to post
Share on other sites

I believe the problem is with the flags you used when registering the Vector type. You're telling AngelScript that this type has a default constructor, destructor, assignment operator, and a copy constructor, which is most likely not the case. These flags are extremely important to get right, as these are what AngelScript will use to know how the type is to be handled in the native calling conventions. 

 

 

The way you've registered the type will tell AngelScript that values of this type must be returned in memory by a function, this means that AngelScript will reserve space for the value, and pass an extra hidden pointer to the function as the first argument. Since the C++ function isn't expecting this hidden argument, it ends up using that pointer as the object pointer which is not correct and thus causes the application to crash.

 

Even without seeing the C++ implementation of the GtVector class, my bet is that the correct flag to use is asOBJ_APP_CLASS_C. You should most likely also add to that the flag asOBJ_APP_CLASS_ALLFLOATS so AngelScript will know the type is composed of only floats or doubles. 

 

Reference: Value types and native calling conventions

 

 

The crash doesn't happen on msvc, because it has a different ABI, than llvm/gnuc on does. On msvc it's enough for the type to have the default constructor for it to be returned in memory, so even though CDAK is not correct, msvc only looked at C and ignored the rest. On llvm/gnuc it is the existance of the destructor or copy constructor that tells if the type should be returned in memory or not.

0

Share this post


Link to post
Share on other sites

The configuration you suggested does solve the issue, below is the new method to register.

ret = engine->RegisterObjectType("Vector", sizeof(GtVector), asOBJ_VALUE | asOBJ_APP_CLASS_CA | asOBJ_APP_CLASS_ALLFLOATS); assert( ret >= 0 );

 

Looking at my vector class, I did have a default constructor and assignment operator, but no explicit copy constructor or deconstructor.

 

I believe part of my problem was a confusion about what I was passing in.  I had assumed the the types being passed in for constructor/deconstructor/ect... dealt with what I was going to register on the class with the engine, not the actual class itself.  I now understand the separation of these two concepts.

 

I apprecaite the help, thank you very much!

1

Share this post


Link to post
Share on other sites

I did the exact same thing for Ogre::Vector3, etc.

The all floats flag is a godsend since I can't (or rather: won't) modify core Ogre code to add copy constructors. :)

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