crash in ctx->GetLineNumber

Started by
11 comments, last by WitchLord 11 years, 1 month ago

Hi smile.png

script code:


// Global scope
Object @obj = CraeteObject();

 


// C++

Object *CreateObject()
{
    asIScriptContext *ctx = asGetActiveContext();


    assert( ctx );


    int stack_size = ctx->GetCallstackSize();


    if( stack_size > 0 )
    {    
        const char *script_section;


        int line = ctx->GetLineNumber(0, 0, &script_section); // Crash
    }
}
 

Advertisement

Thanks. I'll look into this.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I couldn't recreate the problem. I believe this has already been fixed in the latest revision.

Could you try the latest revision and let me know if the problem still happens for you?

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

in revision 1564 - problem resolved itselfsmile.png

Hi egane)

in revision 1564 - problem resolved itselfsmile.png

I made ??a mistake - Its not true!

I couldn't recreate the problem. I believe this has already been fixed in the latest revision.

Could you try the latest revision and let me know if the problem still happens for you?

I had to strain to find it)

So! Bug show, if we use empty file, but not empty as this "" - emty as that " // not use source"!

for reproducte bug, you a need use two files!

First file:


Text @a = scene.Cr();
 

Second file:


// file with out work body!
 

Scene::Cr


void *Scene::Cr()
{
    asIScriptContext *ctx = asGetActiveContext();
    const char *script_section;
    int line = ctx->GetLineNumber(0, 0, &script_section);
    return nullptr;
}
 

if not use second file, bug not showing

Thanks. I'll try again with this additional information.

May I ask how on earth you're coming up with all these odd scenarios? wink.png

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I'm wondering about that as well :) You catch around two bugs every week :D

a WIP 2d game engine: https://code.google.com/p/modulusengine/

English is not my first language, so do feel free to correct me :)

I'm sorry, but I still can't reproduce the problem.

I wrote the following test based on what you provided:


 
class TestLN
{
public:
void *TestLineNumber()
{
    asIScriptContext *ctx = asGetActiveContext();
    const char *script_section;
    int line = ctx->GetLineNumber(0, 0, &script_section);
    return 0;
}
};
 

bool Test()
{
    bool fail = false;

    // Test crash in GetLineNumber
    // http://www.gamedev.net/topic/638656-crash-in-ctx-getlinenumber/
    {
        asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
        engine->RegisterInterface("foo");
        engine->RegisterObjectType("Test", 0, asOBJ_REF | asOBJ_NOCOUNT);
        engine->RegisterObjectMethod("Test", "foo @TestLineNumber()", asMETHOD(TestLN, TestLineNumber), asCALL_THISCALL);
 
        TestLN t;
        engine->RegisterGlobalProperty("Test test", &t);
 
        asIScriptModule *mod = engine->GetModule("test", asGM_ALWAYS_CREATE);
        mod->AddScriptSection("a","foo @f = test.TestLineNumber();");
        mod->AddScriptSection("b"," // nothing to compile");
        int r = mod->Build();
        if( r < 0 )
            TEST_FAILED;
        engine->Release();
    }
    return fail;
}


What do I need to change to reproduce the crash?

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

What do I need to change to reproduce the crash?

my engine can use multiply tabs, and any tab use asIScritpEngine. If exemple i open 5 tabs in debug mode, script compilation time ~2300 msec ( 5 tabs is over 10 second ), I all time use save and load byte code smile.png

Problem show after save and load byte code, use can use this exemple:


class CBytecodeStream : public asIBinaryStream
{
public:
    CBytecodeStream() {wpointer = 0;rpointer = 0;}


    void Write(const void *ptr, asUINT size) 
    {
        if( size == 0 ) 
            return; 
        buffer.resize(buffer.size() + size);
        memcpy(&buffer[wpointer], ptr, size); 
        wpointer += size;
    }
    void Read(void *ptr, asUINT size) 
    {
        memcpy(ptr, &buffer[rpointer], size); 
        rpointer += size;
    }


    int rpointer;
    int wpointer;
    std::vector<asBYTE> buffer;
} script_stream;


class TestLN
{
public:
    void *TestLineNumber()
    {
        asIScriptContext *ctx = asGetActiveContext();
        const char *script_section;
        int line = ctx->GetLineNumber(0, 0, &script_section);
        return 0;
    }
};


void Reg( asIScriptEngine *engine ){


    engine->RegisterInterface("foo");
    engine->RegisterObjectType("Test", 0, asOBJ_REF | asOBJ_NOCOUNT);
    engine->RegisterObjectMethod("Test", "foo @TestLineNumber()", asMETHOD(TestLN, TestLineNumber), asCALL_THISCALL);


    TestLN t;
    engine->RegisterGlobalProperty("Test test", &t);
}


bool Test()
{
    bool fail = false;


    // Test crash in GetLineNumber
    // http://www.gamedev.net/topic/638656-crash-in-ctx-getlinenumber/
    {
        asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);


        Reg( engine );


        asIScriptModule *mod = engine->GetModule("test", asGM_ALWAYS_CREATE);
        mod->AddScriptSection("b"," // nothing to compile");
        mod->AddScriptSection("a","foo @f = test.TestLineNumber();");
        int r = mod->Build();


        script_stream.wpointer = 0;
        mod->SaveByteCode( &script_stream );


        asIScriptEngine *engine2 = asCreateScriptEngine(ANGELSCRIPT_VERSION);
        asIScriptModule *mod2 = engine2->GetModule(0, asGM_ALWAYS_CREATE );


        Reg( engine2 );


        script_stream.rpointer = 0;
        mod2->LoadByteCode( &script_stream );


        assert( r >= 0 );
        engine->Release();
    }
    return fail;
}
 

I'm wondering about that as well smile.png You catch around two bugs every week biggrin.png

the Russian saying - not I such, life suchrolleyes.gif

that's really deep...

a WIP 2d game engine: https://code.google.com/p/modulusengine/

English is not my first language, so do feel free to correct me :)

This topic is closed to new replies.

Advertisement