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

Returning text crashes as with Mingw 4.71 but not with 4.4.1

6 posts in this topic

The following is a short summary of the code that crashes angelscript in 4.7.1 but not in 4.4.1:

 

struct A {
    A() {}
    static void Constructor(A *self) {new(self) A();}
    static void Destructor(A *memory) {memory->~A();}
    std::string getText() {return this->text;}
    std::string text;
    A getA() {return A();}
};

____Code run in Angelscript____:
void main() {
    A a;
    string text = a.getA().getText();
}

 

I have appended a full runnable example below since it might just be that I am registering things in the wrong way (lets hope so).

It appears to be the case that running a function that returns text from an object that was created within angelscript causes a crash.

 


#include <angelscript.h>
#include <add_on/scriptstdstring/scriptstdstring.h>
#include <add_on/scriptbuilder/scriptbuilder.h>
#include <stdio.h>
#include <assert.h>
#include <iostream>

void MessageCallback(const asSMessageInfo *msg, void *param) {
  const char *type = "ERR ";
  if( msg->type == asMSGTYPE_WARNING )
    type = "WARN";
  else if( msg->type == asMSGTYPE_INFORMATION )
    type = "INFO";
  printf("%s (%d, %d) : %s : %s\n", msg->section, msg->row, msg->col, type, msg->message);
}

void print(const std::string &in) {
    std::cout << in << std::endl;
}

struct A {
    A() {}
    static void Constructor(A *self) {new(self) A();}
    static void Destructor(A *memory) {memory->~A();}
    std::string getText() {return this->text;}
    std::string text;
    A getA() {return A();}
};

void registerA(asIScriptEngine *engine) {
    std::string name = "A";
    int r = engine->RegisterObjectType(name.c_str(), sizeof(A), asOBJ_VALUE | asOBJ_APP_CLASS | asOBJ_APP_CLASS_CONSTRUCTOR); assert( r >= 0 );
    r = engine->RegisterObjectBehaviour(name.c_str(), asBEHAVE_CONSTRUCT, std::string("void f()").c_str(), asFUNCTION(A::Constructor), asCALL_CDECL_OBJLAST); assert( r >= 0 );
    r = engine->RegisterObjectBehaviour(name.c_str(), asBEHAVE_DESTRUCT, "void f()", asFUNCTION(A::Destructor), asCALL_CDECL_OBJLAST); assert( r >= 0 );
    r = engine->RegisterObjectMethod("A", "string getText()", asMETHOD(A,getText), asCALL_THISCALL);assert( r >= 0 );
    r = engine->RegisterObjectMethod("A", "A getA()", asMETHOD(A,getA), asCALL_THISCALL);assert( r >= 0 );
}

std::string app = "void main() {A a;string text = a.getA().getText();}";

int main() {
    asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
    int r = engine->SetMessageCallback(asFUNCTION(MessageCallback), 0, asCALL_CDECL); assert( r >= 0 );
    RegisterStdString(engine);
    r = engine->RegisterGlobalFunction("void print(const string &in)", asFUNCTION(print), asCALL_CDECL); assert( r >= 0 );

    registerA(engine);

    CScriptBuilder builder;
    r = builder.StartNewModule(engine, "MyModule"); if( r < 0 ) {printf("Unrecoverable error while starting a new module.\n");return 0;}
    r = builder.AddSectionFromMemory("TestSection", app.c_str());if( r < 0 ) {printf("Please correct the errors in the script and try again.\n");return 0;}
    r = builder.BuildModule(); if( r < 0 ) {printf("Please correct the errors in the script and try again.\n");return 0;}

    asIScriptModule *mod = engine->GetModule("MyModule");
    asIScriptFunction *func = mod->GetFunctionByDecl("void main()"); if( func == 0 ) {printf("The script must have the function 'void main()'. Please add it and try again.\n");return 0;}
    asIScriptContext *ctx = engine->CreateContext();
    ctx->Prepare(func);
    r = ctx->Execute(); if( r != asEXECUTION_FINISHED and r == asEXECUTION_EXCEPTION) {printf("An exception '%s' occurred. Please correct the code and try again.\n", ctx->GetExceptionString());}
}

 

 

0

Share this post


Link to post
Share on other sites
Which version of AngelScript are you using? MinGW changed the ABI for native calling conventions with version 4.7. I updated AngelScript according to the new ABI only with version 2.25.1. So earlier versions of AngelScript will not work with MinGW 4.7 or later.
0

Share this post


Link to post
Share on other sites

I am using the latest version: 2.26.1. (I am the dude that first brought up the issue with mingw 4.7.1 behaving strangely a few months back).

0

Share this post


Link to post
Share on other sites

Oh, I'm sorry, I checked the change list to see when exactly I had changed AngelScript. I should have noticed your name in the credit for that fix. ;)

 

Would you mind just giving the latest WIP from the svn a try? I can't be certain this problem has been fixed, but I did do some tweaks for MinGW as I was getting MinGW 64bit support up to date.

 

Let me know if it still doesn't work and I'll take a closer look on this problem.

0

Share this post


Link to post
Share on other sites

I tried the latest svn version via sourceforge tarball download of trunk, same problem. 

 

As usual I caution that I may not be registering things properly and this might just be my fault (though i did try my best to do things correctly).

0

Share this post


Link to post
Share on other sites

No, since it works on MinGW 4.4.1 and not MinGW 4.7.1 I think it is more likely some other difference the ABI that I didn't fix in 2.25.1.

 

I'll investigate it.

0

Share this post


Link to post
Share on other sites

Well, contrary to my initial thoughts I found that it was indeed that the class A had been registered incorrectly. Even though this class doesn't have it's own destructor, copy constructor, or assignment operator it should still be registered with the flags asOBJ_APP_CLASS_CDAK. Why? Because the member 'string text' has all of these.

 

Even I wasn't aware of this, and I'll have to update the manual with this new knowledge.

 

I'm not sure why this didn't break with MinGW 4.4.1, as I don't have that version of MinGW to test with. But I did test it with MinGW 4.6.2 and it also failed in the same way as MinGW 4.7.1 so this was not related to the ABI changes that were made in MinGW 4.7.

 

The new asGetTypeTraits<type>() helper function that you helped me implement returns the correct flags.

 
int r = engine->RegisterObjectType("A", sizeof(A), asOBJ_VALUE | asGetTypeTraits<A>()); assert( r >= 0 );
Edited by Andreas Jonsson
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