• Advertisement
Sign in to follow this  

crash in ctx->GetLineNumber

This topic is 1789 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
    }
}
 

 

Share this post


Link to post
Share on other sites
Advertisement

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? 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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?

Edited by Andreas Jonsson

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Finally. I've reproduced the problem now. Thanks a lot for the help.

 

I'll work on the fix, and should have it ready for check-in by tonight.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement