フォーラムメモ Edit

自分自身のプロパティアクセサを呼び出すとフリーズ Edit

  • ライブラリバージョン : r564
コールトレース
  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
	GameProject.exe!asCArray<asCScriptFunction *>::operator[](unsigned int index=0)  Line 147 + 0x6 Bytes	C++
 	GameProject.exe!asCContext::CallInterfaceMethod(asCScriptFunction * func=0x0a8e1058)  Line 1254 + 0x15 Bytes	C++
 	GameProject.exe!asCContext::ExecuteNext()  Line 2790	C++
 	GameProject.exe!asCContext::Execute()  Line 1004 + 0x8 Bytes	C++
 	GameProject.exe!base::ags::ContextHandle::execute()  Line 104 + 0x23 Bytes	C++
 	GameProject.exe!app::scene::SceneASTest::onSceneStart()  Line 67	C++
 	GameProject.exe!app::Application::beginSceneProcess()  Line 191 + 0x23 Bytes	C++
 	GameProject.exe!app::Application::execute()  Line 99 + 0xc Bytes	C++
 	GameProject.exe!`anonymous namespace'::t_executeApplication()  Line 50 + 0xb Bytes	C++
 	GameProject.exe!app::EntryPoint::run()  Line 73	C++
 	GameProject.exe!wmain(int __formal=1, int __formal=1)  Line 16	C++
 	GameProject.exe!__tmainCRTStartup()  Line 594 + 0x19 Bytes	C
 	GameProject.exe!wmainCRTStartup()  Line 414	C
ASコード
すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 
-
|
|
|
!
 
 
-
|
-
|
!
|
-
|
!
|
|
!
 
 
 
-
|
|
!
class Vector3
{
    float x;
    float y;
    float z;
};
 
class Hoge
{
    const Vector3 get_pos()const
    {
        return mPos;
    }
    const Vector3 foo()const
    {
        return pos;
    }
 
    Vector3 mPos;
};
 
 
void main()
{
    Hoge h;
    const Vector3 vec = h.foo();
}

すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 
-
|
|
|
!
 
 
-
|
|
|
|
!
 
 
 
-
|
|
|
|
!
 
class Vector3
{
    float x;
    float y;
    float z;
};
 
class Hoge
{
    const Vector3 get_pos() { return mPos; }
    const Vector3 foo() { return pos;  }
    const Vector3 zoo() { return get_pos(); }
    Vector3 mPos;
};
 
 
void main()
{
    Hoge h;
    Vector3 vec;
    vec = h.zoo(); // ok
    vec = h.foo(); // runtime exception
}

__Hoge_foo.txt

  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
Temps: 1
 
    0   0 *    PUSH     1
    1   1 *    PshV4    v0
    2   2 *    CALLSYS  17           (void _builtin_object_::_beh_4_())
- 11,27 -
    4   1 *    SUSPEND
    5   1 *    PSF      v0
    6   2 *    CALLINTF 86           (const Vector3 Hoge::get_pos())
    8   1 *    STOREOBJ v1
    9   1 *    LOADOBJ  v1
   10   1 * 0:
   10   1 *    FREE     v0, 11276368
   12   0 *    RET      1

__Hoge_zoo.txt

  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
Temps: 1
 
    0   0 *    PUSH     1
    1   1 *    PshV4    v0
    2   2 *    CALLSYS  17           (void _builtin_object_::_beh_4_())
- 12,27 -
    4   1 *    SUSPEND
    5   1 *    PshV4    v0
    6   2 *    CALLINTF 86           (const Vector3 Hoge::get_pos())
    8   1 *    STOREOBJ v1
    9   1 *    LOADOBJ  v1
   10   1 * 0:
   10   1 *    FREE     v0, 11276368
   12   0 *    RET      1

opAssignを定義するとコンパイル時にAssert Edit

  • ライブラリバージョン : 2.18.1
エラーメッセージ
Assertion failed: tempVariables.GetLength() == 0, file ..\..\source\as_compiler.cpp, line 643
コールトレース
  0
  1
  2
  3
 	msvcr80d.dll!_wassert(const wchar_t * expr=0x007013cc, const wchar_t * filename=0x00701174, unsigned int lineno=643)  行 212	C
 	GameProject.exe!asCCompiler::CompileStatementBlock(asCScriptNode * block=0x0a8c1640, bool ownVariableScope=false, bool * hasReturn=0x0012b2e3, asCByteCode * bc=0x0012b2a0)  行 643 + 0x29 バイト	C++
 	GameProject.exe!asCCompiler::CompileFunction(asCBuilder * builder=0x0a8e2b08, asCScriptCode * script=0x0a8e2800, asCScriptNode * func=0x0a8e2878, asCScriptFunction * outFunc=0x0a8e3c10)  行 324	C++
 	GameProject.exe!asCBuilder::CompileFunctions()  行 524	C++
 	GameProject.exe!asCBuilder::Build()  行 184	C++
ASコード
すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 
-
|
|
|
-
|
!
|
|
-
|
|
!
!
 
 
-
|
!
class Hoge
{
    int mValue;
    
    Hoge()
    {
        mValue = 0;
    }
    
    Hoge@ opAssign(const Hoge &in aObj)
    {
        mValue = aObj.mValue;
        return @this;
    }
};
 
void main()
{
    Hoge a = Hoge();
}

デストラクタが呼ばれない Edit

すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 
 
 
 
-
!
 
 
-
|
-
|
!
|
-
|
!
|
!
 
 
-
|
-
|
!
|
-
|
!
|
!
 
 
-
|
-
|
!
-
|
!
|
|
!
 
 
-
|
!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
//-----------------------------------------------------------
// script code
 
class ObjType
{
};
 
class HaveObj
{
    HaveObj()
    {
        Print( "HaveObj::ctor\n" );
    }
    ~HaveObj()
    {
        Print( "HaveObj::dtor\n" );
    }
    ObjType o;
};
 
class HaveHandle
{
    HaveHandle()
    {
        Print( "HaveHandle::ctor\n" );
    }
    ~HaveHandle()
    {
        Print( "HaveHandle::dtor\n" );
    }
    ObjType@ o;
};
 
void testCase1()
{
    Print( "testCase1 start\n" );
    {
        HaveObj o;
    }// call o.~HaveObj();
    {
        HaveHandle o;
    }// not call o.~HaveHandle();
    
    Print( "testCase1 end\n" );
} 
 
void main()
{
    testCase1();
}
 
 
//-----------------------------------------------------------
 
 
//-----------------------------------------------------------
// output
 
testCase1 start
HaveObj::ctor
HaveObj::dtor
HaveHandle::ctor
testCase1 end
 
 
//-----------------------------------------------------------

回答
As with any language with automatic memory management, it can be hard to predict when the destructor is called.

In your case you have created a situation where the ordinary reference counting is not enough to control the life time of the objects, so the garbage collector is notified to keep a watch on the object instance. However, the garbage collector is not invoked automatically by the script engine (so that the application will have full control of when that is done). This means that unless you manually call the GC, the object will only be destroyed when you release the script engine.

配列を使った循環参照状態を記述するとメモリリーク Edit

  • ライブラリバージョン : r575
C++コード
すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
-
|
|
|
|
|
-
|
|
!
|
|
-
|
|
!
|
!
 
 
 
 
 
 
 
 
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
!
 
 
 
 
 
#spanend
#spanadd
 
#spanend
#spanadd
//-----------------------------------------------------------
#spanend
#spanadd
// C++ source code
#spanend
#spanadd
namespace
#spanend
#spanadd
{
#spanend
    // alloc counter
    int t_allocCount = 0;
    // alloc function
    void* t_alloc( const size_t aSize )
    {
        ++t_allocCount;
        return std::malloc( aSize );
    }
    // free cuntion
    void t_free( void* aPtr )
    {
        std::free( aPtr );
        --t_allocCount;
    }
#spanadd
}
#spanend
#spanadd
 
#spanend
#spanadd
int main(int argc, char **argv)
#spanend
#spanadd
{
#spanend
    // set allocator
    asSetGlobalMemoryFunctions( t_alloc , t_free );
#spanadd
 
#spanend
    // Create the script engine
    asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
#spanadd
 
#spanend
    // Compile
    asIScriptModule *mod = engine->GetModule(0, asGM_ALWAYS_CREATE);
    mod->AddScriptSection("script", 
        "class Hoge"
        "{"
        "    Hoge(){}"
        "    Hoge(HogeManager&){}"
        "};"
        "class HogeManager"
        "{"
        "    Hoge[] hoges;"
        "};"
        , 0);
    mod->Build();
#spanadd
 
#spanend
    // Release engine
    engine->Release();
#spanadd
 
#spanend
    // check
    assert( t_allocCount == 0 );
#spanadd
}
#spanend
#spanadd
 
#spanend
#spanadd
対処
すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
#spanend
#spanadd
// as_scriptengine.cpp L490付近
#spanend
#spanadd
 
#spanend
#spanadd
    GarbageCollect(asGC_FULL_CYCLE);
#spanend
#spanadd
    FreeUnusedGlobalProperties();
#spanend
#spanadd
    ClearUnusedTypes();
#spanend
#spanadd
 
#spanend
        // もう一度,GCを走らせる
#spanadd
    GarbageCollect(asGC_FULL_CYCLE);
#spanend
#spanadd

enumの文字列かぶりで無限ループ Edit

  • ライブラリバージョン : r575
スクリプトコード
すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 
 
 
 
 
-
|
|
|
|
!
 
 
 
 
 
#spanend
#spanadd
enum Kind
#spanend
#spanadd
{
#spanend
    Kind_A
    , Kind_A // This code gives name conflict error and infinite loop.
#spanadd
};
#spanend
#spanadd
 
#spanend
#spanadd

asGC_ONE_STEPは想定した動きになっているのか Edit

  • ライブラリバージョン : r586
code
すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 
 
 
 
 
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
-
|
!
|
|
-
|
|
|
|
|
!
|
|
|
|
|
!
|
|
|
|
|
|
|
!
 
 
#spanend
#spanadd
void main()
#spanend
#spanadd
{
#spanend
    // Create the script engine
    asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
 
    // Register Function
    RegisterScriptString(engine);
    engine->RegisterGlobalFunction("void Print(string &in)", asFUNCTION(PrintString_Generic), asCALL_GENERIC);
#spanadd
 
#spanend
    // Compile
    asIScriptModule *mod = engine->GetModule(0, asGM_ALWAYS_CREATE);
    mod->AddScriptSection("script", 
        "class Obj{};"
        "class Hoge"
        "{"
        "    Hoge(){ Print(\"ctor\\n\"); }"
        "    ~Hoge(){ Print(\"dtor\\n\"); }"
        "    Obj@ obj;"
        "};"
        "void main()"
        "{"
        "    Hoge hoge;"
        "};"
        , 0);
    mod->Build();
 
    // Context Create
    asIScriptContext *ctx = engine->CreateContext();
#spanadd
 
#spanend
    // Loop
    while ( true )
    {
        // Execute
        printf("----- execute\n");
        ctx->Prepare(mod->GetFunctionIdByDecl("void main()"));
        ctx->Execute();
#spanadd
 
#spanend
        // GC
        const int GC_STEP_COUNT_PER_FRAME = 10000;
        for ( int i = 0; i < GC_STEP_COUNT_PER_FRAME; ++i )
        {
            engine->GarbageCollect(asGC_ONE_STEP);
        }
        
        // Check status
        {
            asUINT currentSize = asUINT();
            asUINT totalDestroyed = asUINT();
            asUINT totalDetected = asUINT();
            engine->GetGCStatistics(&currentSize , &totalDestroyed , &totalDetected );
            printf("(%lu,%lu,%lu)\n" , currentSize , totalDestroyed , totalDetected );
        }
#spanadd
 
#spanend
        // Wait to input key
        while(!getch()){}
    }
#spanadd
 
#spanend
    // Release 
    ctx->Release();
    engine->Release();
#spanadd
}
#spanend
#spanadd
output
  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
#spanend
----- execute
#spanadd
ctor
#spanend
#spanadd
dtor
#spanend
#spanadd
(8,1,0)
#spanend
----- execute
#spanadd
ctor
#spanend
#spanadd
(9,1,0)
#spanend
----- execute
#spanadd
ctor
#spanend
#spanadd
(10,1,0)
#spanend
----- execute
#spanadd
ctor
#spanend
#spanadd
(11,1,0)
#spanend
----- execute
#spanadd
ctor
#spanend
#spanadd
(12,1,0)
#spanend
----- execute
#spanadd
ctor
#spanend
#spanadd
(13,1,0)
#spanend
----- execute
#spanadd
ctor
#spanend
#spanadd
(14,1,0)
#spanend
#spanadd
 
#spanend
#spanadd

as_restore.cppの修正箇所 Edit

revision

r589
Not work on Big Endian Environment(L1398,L1410,L1451,L1473,L1488)
すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
#spanend
#spanadd
// src
#spanend
#spanadd
asWORD w = (asWORD)(tmp[0]>>16);
#spanend
#spanadd
// fixed
#spanend
#spanadd
asWORD w = *(((asWORD*)tmp)+1);
#spanend
#spanadd
 
Not work on Big Endian Environment(L1587,L1600,L1637,L1661,L1678,L1727)
すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
#spanend
#spanadd
// src
#spanend
#spanadd
*bc += asDWORD(w)<<16;
#spanend
#spanadd
// fixed
#spanend
#spanadd
*(((asWORD*)bc)+1) = w;
#spanend
#spanadd
miss spell(L1497)
すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
#spanend
#spanadd
// src
#spanend
#spanadd
asDWORD dw = tmp[2];
#spanend
#spanadd
WRITE_NUM(w);
#spanend
#spanadd
// fixed
#spanend
#spanadd
asDWORD dw = tmp[2];
#spanend
#spanadd
WRITE_NUM(dw);
#spanend
#spanadd
miss spell(L1642,L1666,L1683)
すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
#spanend
#spanadd
// src
#spanend
#spanadd
*(WORD*)bc = w;
#spanend
#spanadd
// fixed
#spanend
#spanadd
*(asWORD*)bc = w;
#spanend
#spanadd
miss spell(L1646)
すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
#spanend
#spanadd
// src
#spanend
#spanadd
*(((WORD*)bc)+1) = w;
#spanend
#spanadd
// fixed
#spanend
#spanadd
*(((asWORD*)bc)+1) = w;
#spanend
#spanadd

テンプレートのメソッドを呼ぶスクリプトコードをSaveByteCode&LoadByteCodeすると落ちる Edit

リビジョン

r589
script code
すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 
 
 
 
 
-
|
|
|
|
!
 
 
#spanend
#spanadd
void main()
#spanend
#spanadd
{
#spanend
    array< int > intArray = {0,1,2};
    uint tmp = intArray.length(); // program stoped while module->LoadByteCode() Processing
#spanadd
};
#spanend
#spanadd
freeze code pos
すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
-
|
|
|
|
|
|
|
|
|
|
|
!
 
 
#spanend
#spanadd
// as_restore.cpp L1937
#spanend
#spanadd
else if( c == asBC_CALL ||
#spanend
#spanadd
         c == asBC_CALLINTF ||
#spanend
#spanadd
         c == asBC_CALLSYS )
#spanend
#spanadd
{
#spanend
#spanadd
    // Translate the index to the func id
#spanend
#spanadd
    int *fid = (int*)&bc[n+1];
#spanend
#spanadd
    *fid = FindFunction(*fid)->id; // null pointer access
#spanend
#spanadd
}
#spanend
#spanadd

fix patch Edit

as_restore.cpp
すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
 
 
 
 
 
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
!
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
!
|
|
!
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
!
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
!
|
|
!
|
|
|
|
|
-
|
|
|
|
|
|
|
|
!
|
|
!
 
 
 
 
 
 
 
 
 
 
 
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
!
|
-
!
|
-
|
!
|
|
|
|
|
|
|
|
|
!
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
!
|
|
!
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
|
!
|
|
!
|
|
|
|
|
|
|
|
|
|
|
!
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
!
|
|
|
|
|
-
|
|
|
|
|
!
|
|
|
|
|
-
|
|
|
|
|
!
|
|
|
|
|
|
|
|
!
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
!
|
|
|
|
|
|
|
|
!
 
 
#spanend
#spanadd
void asCRestore::WriteObjectType(asCObjectType* ot) 
#spanend
#spanadd
{
#spanend
#spanadd
    char ch;
#spanend
#spanadd
 
#spanend
#spanadd
    // Only write the object type name
#spanend
#spanadd
    if( ot )
#spanend
#spanadd
    {
#spanend
#spanadd
        // Check for template instances/specializations
#spanend
#spanadd
        if( ot->templateSubType.GetTokenType() != ttUnrecognizedToken &&
#spanend
#spanadd
            ot != engine->defaultArrayObjectType )
#spanend
#spanadd
        {
#spanend
#spanadd
            ch = 'a';
#spanend
#spanadd
            WRITE_NUM(ch);
#spanend
#spanadd
 
#spanend
#spanadd
            if( ot->templateSubType.IsObject() )
#spanend
#spanadd
            {
#spanend
#spanadd
                ch = 's';
#spanend
#spanadd
                WRITE_NUM(ch);
#spanend
#spanadd
                WriteObjectType(ot->templateSubType.GetObjectType());
#spanend
#spanadd
 
#spanend
#spanadd
                if( ot->templateSubType.IsObjectHandle() )
#spanend
#spanadd
                    ch = 'h';
#spanend
#spanadd
                else
#spanend
#spanadd
                    ch = 'o';
#spanend
                
#spanadd
                WRITE_NUM(ch);
#spanend
#spanadd
#if 1
#spanend
                ch = 'o';
                WRITE_NUM(ch);
#spanadd
                WriteString(&ot->name);
#spanend
#spanadd
#endif
#spanend
#spanadd
            }
#spanend
#spanadd
            else
#spanend
#spanadd
            {
#spanend
#spanadd
                ch = 't';
#spanend
#spanadd
                WRITE_NUM(ch);
#spanend
#spanadd
                eTokenType t = ot->templateSubType.GetTokenType();
#spanend
#spanadd
                WRITE_NUM(t);
#spanend
#spanadd
            }
#spanend
#spanadd
        }
#spanend
#spanadd
        else if( ot->flags & asOBJ_TEMPLATE_SUBTYPE )
#spanend
#spanadd
        {
#spanend
#spanadd
            ch = 's';
#spanend
#spanadd
            WRITE_NUM(ch);
#spanend
#spanadd
            WriteString(&ot->name);
#spanend
#spanadd
        }
#spanend
#spanadd
        else
#spanend
#spanadd
        {
#spanend
#spanadd
            ch = 'o';
#spanend
#spanadd
            WRITE_NUM(ch);
#spanend
#spanadd
            WriteString(&ot->name);
#spanend
#spanadd
        }
#spanend
#spanadd
    }
#spanend
#spanadd
    else
#spanend
#spanadd
    {
#spanend
#spanadd
        ch = '\0';
#spanend
#spanadd
        WRITE_NUM(ch);
#spanend
#spanadd
    }
#spanend
#spanadd
}
#spanend
#spanadd
 
#spanend
#spanadd
 
#spanend
#spanadd
asCObjectType* asCRestore::ReadObjectType() 
#spanend
#spanadd
{
#spanend
#spanadd
    asCObjectType *ot;
#spanend
#spanadd
    char ch;
#spanend
#spanadd
    READ_NUM(ch);
#spanend
#spanadd
    if( ch == 'a' )
#spanend
#spanadd
    {
#spanend
#spanadd
        READ_NUM(ch);
#spanend
#spanadd
        if( ch == 's' )
#spanend
#spanadd
        {
#spanend
#spanadd
#if 0
#spanend
#spanadd
            ot = ReadObjectType();
#spanend
#spanadd
            asCDataType dt = asCDataType::CreateObject(ot, false);
#spanend
#spanadd
 
#spanend
#spanadd
            READ_NUM(ch);
#spanend
#spanadd
            if( ch == 'h' )
#spanend
#spanadd
                dt.MakeHandle(true);
#spanend
#spanadd
 
#spanend
#spanadd
            dt.MakeArray(engine);
#spanend
#spanadd
            ot = dt.GetObjectType();
#spanend
#spanadd
            
#spanend
#spanadd
            asASSERT(ot);
#spanend
#spanadd
#else
#spanend
            asCObjectType* subOT = ReadObjectType();
            asCDataType dt = asCDataType::CreateObject(subOT, false);
            READ_NUM(ch);
            if ( ch == 'h' )
            {
                dt.MakeHandle(true);
            }
            else if ( ch == 'o' )
            {
            }
            else
            {
                assert(false);
            }
            asCObjectType* tmplOT = ReadObjectType();
#spanadd
            dt.MakeTemplateInstanceType(engine,tmplOT);
#spanend
            ot = dt.GetObjectType();
#spanadd
#endif
#spanend
#spanadd
        }
#spanend
#spanadd
        else
#spanend
#spanadd
        {
#spanend
#spanadd
            eTokenType tokenType;
#spanend
#spanadd
            READ_NUM(tokenType);
#spanend
#spanadd
            asCDataType dt = asCDataType::CreatePrimitive(tokenType, false);
#spanend
#spanadd
            dt.MakeArray(engine);
#spanend
#spanadd
            ot = dt.GetObjectType();
#spanend
#spanadd
            
#spanend
#spanadd
            asASSERT(ot);
#spanend
#spanadd
        }
#spanend
#spanadd
    }
#spanend
#spanadd
    else if( ch == 's' )
#spanend
#spanadd
    {
#spanend
#spanadd
        // Read the name of the template subtype
#spanend
#spanadd
        asCString typeName;
#spanend
#spanadd
        ReadString(&typeName);
#spanend
#spanadd
 
#spanend
#spanadd
        // Find the template subtype
#spanend
#spanadd
        for( asUINT n = 0; n < engine->templateSubTypes.GetLength(); n++ )
#spanend
#spanadd
        {
#spanend
#spanadd
            if( engine->templateSubTypes[n] && engine->templateSubTypes[n]->name == typeName )
#spanend
#spanadd
            {
#spanend
#spanadd
                ot = engine->templateSubTypes[n];
#spanend
#spanadd
                break;
#spanend
#spanadd
            }
#spanend
#spanadd
        }
#spanend
#spanadd
 
#spanend
#spanadd
        // TODO: Should give a friendly error in case the template type isn't found
#spanend
#spanadd
        asASSERT(ot);
#spanend
#spanadd
    }
#spanend
#spanadd
    else if( ch == 'o' )
#spanend
#spanadd
    {
#spanend
#spanadd
        // Read the object type name
#spanend
#spanadd
        asCString typeName;
#spanend
#spanadd
        ReadString(&typeName);
#spanend
#spanadd
 
#spanend
#spanadd
        if( typeName.GetLength() && typeName != "_builtin_object_" && typeName != "_builtin_function_" )
#spanend
#spanadd
        {
#spanend
#spanadd
            // Find the object type
#spanend
#spanadd
            ot = module->GetObjectType(typeName.AddressOf());
#spanend
#spanadd
            if( !ot )
#spanend
#spanadd
                ot = engine->GetObjectType(typeName.AddressOf());
#spanend
#spanadd
            
#spanend
#spanadd
            asASSERT(ot);
#spanend
#spanadd
        }
#spanend
#spanadd
        else if( typeName == "_builtin_object_" )
#spanend
#spanadd
        {
#spanend
#spanadd
            ot = &engine->scriptTypeBehaviours;
#spanend
#spanadd
        }
#spanend
#spanadd
        else if( typeName == "_builtin_function_" )
#spanend
#spanadd
        {
#spanend
#spanadd
            ot = &engine->functionBehaviours;
#spanend
#spanadd
        }
#spanend
#spanadd
        else
#spanend
#spanadd
            assert( false );
#spanend
#spanadd
    }
#spanend
#spanadd
    else
#spanend
#spanadd
    {
#spanend
#spanadd
        // No object type
#spanend
#spanadd
        assert( ch == '\0' );
#spanend
#spanadd
        ot = 0;
#spanend
#spanadd
    }
#spanend
#spanadd
 
#spanend
#spanadd
    return ot;
#spanend
#spanadd
}
#spanend
#spanadd
as_datatype.h
すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
#spanend
#spanadd
    int MakeHandle(bool b, bool acceptHandleForScope = false);
#spanend
#spanadd
    int MakeArray(asCScriptEngine *engine);
#spanend
#spanadd
    int MakeReference(bool b);
#spanend
#spanadd
    int MakeReadOnly(bool b);
#spanend
#spanadd
    int MakeHandleToConst(bool b);
#spanend
#spanadd
#if 1
#spanend
    int MakeTemplateInstanceType(asCScriptEngine *engine,asCObjectType*);
#spanadd
#endif
#spanend
#spanadd
as_datatype.cpp
すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 
 
 
 
 
 
 
 
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
!
 
 
 
 
 
#spanend
#spanadd
#if 1
#spanend
#spanadd
int asCDataType::MakeTemplateInstanceType(asCScriptEngine *engine,asCObjectType* templateOT)
#spanend
#spanadd
{
#spanend
#spanadd
    bool tmpIsReadOnly = isReadOnly;
#spanend
#spanadd
    isReadOnly = false;
#spanend
#spanadd
    asCObjectType *at = engine->GetTemplateInstanceType(templateOT, *this);
#spanend
#spanadd
    isReadOnly = tmpIsReadOnly;
#spanend
#spanadd
 
#spanend
#spanadd
    isObjectHandle = false;
#spanend
#spanadd
    isConstHandle = false;
#spanend
#spanadd
    
#spanend
#spanadd
    objectType = at;
#spanend
#spanadd
    tokenType = ttIdentifier;
#spanend
#spanadd
 
#spanend
#spanadd
    return 0;
#spanend
#spanadd
}
#spanend
#spanadd
#endif
#spanend
#spanadd

as_restore.cppの修正箇所 その2 Edit


r594

Not work on Big Endian Environment(L1580,L1615,L1624,L1699,L1710)
すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
#spanend
#spanadd
// src
#spanend
#spanadd
*bc++ = b;
#spanend
#spanadd
// fixed
#spanend
#spanadd
*(asBYTE*)(bc) = b;
#spanend
++bc;
#spanadd

Not work on Big Endian Environment(L1600.L1637,L1661,L1678,L1727)
すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
#spanend
#spanadd
// src
#spanend
#spanadd
*bc = b;
#spanend
#spanadd
// fixed
#spanend
#spanadd
*(asBYTE*)(bc) = b;
#spanend
#spanadd

load byte code failed Edit

Revision

r595

Assertion failed at loading byte code.
すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 
 
 
 
 
 
 
 
 
 
 
-
|
|
|
!
 
 
#spanend
#spanadd
// Succeed case
#spanend
#spanadd
class Hoge {};
#spanend
#spanadd
class HogeManager
#spanend
#spanadd
{
#spanend
    array< Hoge >@ hogeArray;
#spanadd
};
#spanend
#spanadd
すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 
 
 
 
 
 
 
 
-
|
|
|
!
 
 
 
 
 
#spanend
#spanadd
// Failed case
#spanend
#spanadd
class HogeManager
#spanend
#spanadd
{
#spanend
    array< Hoge >@ hogeArray;
#spanadd
};
#spanend
#spanadd
class Hoge {};
#spanend
#spanadd
Message
Assertion failed: ot, file ..\..\source\as_restore.cpp, line 1244

load byte code failed part2 Edit

Revision

r609

Assertion failed at loading byte code.
すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 
 
 
 
 
 
 
 
-
|
|
-
|
!
|
!
 
 
 
 
 
#spanend
#spanadd
// Failed case
#spanend
#spanadd
class HogeManager
#spanend
#spanadd
{
#spanend
    HogeManager()
    {
        array< Hoge >@ hogeArray;
    }
#spanadd
};
#spanend
#spanadd
class Hoge {};
#spanend
#spanadd
Message
Assertion failed: ot, file ..\..\source\as_restore.cpp, line 1299

memory leak part2 Edit

Revision

r604

Add 'array' object method
すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 
 
 
 
 
 
 
 
-
|
|
|
!
 
 
 
 
 
-
|
|
|
|
|
!
 
 
#spanend
#spanadd
// scriptarray.cpp
#spanend
#spanadd
namespace
#spanend
#spanadd
{
#spanend
    void t_hoge(asIScriptGeneric*){}    
#spanadd
}
#spanend
#spanadd
void RegisterScriptArray_Generic(asIScriptEngine *engine)
#spanend
#spanadd
{
#spanend
    ...
    r = engine->RegisterObjectMethod("array<T>", "void hoge(const T&in)" , asFUNCTION(t_hoge), asCALL_GENERIC); assert( r >= 0 );
    
#spanadd
}
#spanend
#spanadd

main.cpp
すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 
 
 
 
 
 
 
 
 
 
 
-
|
|
|
|
|
-
|
|
!
|
|
-
|
|
!
|
!
 
 
 
 
 
 
 
 
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
!
 
 
#spanend
#spanadd
//-----------------------------------------------------------
#spanend
#spanadd
// C++ source code
#spanend
#spanadd
namespace
#spanend
#spanadd
{
#spanend
    // alloc counter
    int t_allocCount = 0;
    // alloc function
    void* t_alloc( const size_t aSize )
    {
        ++t_allocCount;
        return std::malloc( aSize );
    }
    // free cuntion
    void t_free( void* aPtr )
    {
        std::free( aPtr );
        --t_allocCount;
    }
#spanadd
}
#spanend
#spanadd
 
#spanend
#spanadd
int main(int argc, char **argv)
#spanend
#spanadd
{
#spanend
    // set allocator
    asSetGlobalMemoryFunctions( t_alloc , t_free );
#spanadd
 
#spanend
    // Create the script engine
    asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
#spanadd
 
#spanend
    // Register array class
    RegisterScriptArray_Generic(engine);
#spanadd
 
#spanend
    // Compile
    asIScriptModule *mod = engine->GetModule(0, asGM_ALWAYS_CREATE);
    mod->AddScriptSection("script", 
        "class Hoge"
        "{"
        "    HogeManager@ hogeManager;"
        "};"
        "class HogeManager"
        "{"
        "    array< Hoge >@ hoges;"
        "};"
        , 0);
    mod->Build();
#spanadd
 
#spanend
    // Release engine
    engine->Release();
#spanadd
 
#spanend
    // check
    assert( t_allocCount == 0 ); // assertion failed
#spanadd
 
#spanend
    return 0;
#spanadd
}
#spanend
#spanadd

load byte code failed part3 Edit

Revision

r609
Script Code
すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 
 
 
 
 
 
 
 
-
|
|
|
!
 
 
#spanend
#spanadd
array< ColorKind > COLOR_KIND_TABLE = { ColorKind_Red };
#spanend
#spanadd
enum ColorKind
#spanend
#spanadd
{
#spanend
    ColorKind_Red
#spanadd
};
#spanend
#spanadd
Call stack trace

Maybe null pointer access.

msvc8.exe!asCRestore::TranslateFunction(asCScriptFunction * func=0x003ed990) Line 2011 + 0x11 Byte C++

msvc8.exe!asCRestore::Restore() Line 358 C++

msvc8.exe!asCModule::LoadByteCode(asIBinaryStream * in=0x00ad7018) Line 1237 + 0xb Byte C++

load byte code failed part4 Edit

Revision

r613
Script Code
すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 
 
 
 
 
 
 
 
 
 
 
-
|
|
|
|
|
!
 
 
#spanend
#spanadd
interface IObj {};
#spanend
#spanadd
class Hoge : IObj {};
#spanend
#spanadd
void main()
#spanend
#spanadd
{
#spanend
    Hoge h;
    IObj@ objHandle = h;
    Hoge@ hogeHandle = cast< Hoge@ >( objHandle );
#spanadd
};
#spanend
#spanadd

Crash at as_context.cpp L2866.

build failed Edit

Revision

r614
ScriptCode
すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 
 
 
 
 
 
 
 
-
|
|
|
!
 
 
 
 
 
-
|
|
-
|
|
|
!
|
|
!
 
 
#spanend
#spanadd
class Obj {};
#spanend
#spanadd
class Hoge
#spanend
#spanadd
{
#spanend
    const Obj obj()const { return Obj(); }
#spanadd
};
#spanend
#spanadd
class Foo
#spanend
#spanadd
{
#spanend
    Foo()
    {
        Hoge h;
        Obj tmpObj = h.obj(); /* OK */
        mObj = h.obj(); /* Build failed */
    }
    Obj mObj;
#spanadd
};
#spanend
#spanadd

    ホーム 一覧 検索 最終更新 バックアップ リンク元   ヘルプ   最終更新のRSS