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

Debug problems

21 posts in this topic

v1.9.0 Until recently, I've just been using a retail build of the angelscript.lib. My game seemed to be working great. But I just tried making a debug compile of everything, and now my program cant even run... What I am wondering is what sort of things might be causing this assert to occur:
Assertion failed: tempVariables.GetLength() == 0, file d:\co
de\angelscript_1_9_0\source\as_compiler.cpp, line 364

// This is where AS was at the time:
Lands.exe!_NMSG_WRITE(int rterrnum=10)  Line 195	C
Lands.exe!abort()  Line 44 + 0x7	C
Lands.exe!_assert(const char * expr=0x0055e928, const char * filename=0x0055e870, unsigned int lineno=364)  Line 306	C
Lands.exe!asCCompiler::CompileStatementBlock(asCScriptNode * block=0x01211698, bool ownVariableScope=false, bool * hasReturn=0x0012f1e7, asCByteCode * bc=0x0012f1d4)  Line 364 + 0x27	C++
Lands.exe!asCCompiler::CompileFunction(asCBuilder * builder=0x01065a80, asCScriptCode * script=0x01070b98, asCScriptNode * func=0x0120d090)  Line 208	C++
Lands.exe!asCBuilder::CompileFunctions()  Line 245 + 0x38	C++
Lands.exe!asCBuilder::Build()  Line 119	C++
Lands.exe!asCModule::Build(asIOutputStream * out=0x00570f50)  Line 98 + 0xb	C++
Lands.exe!asCScriptEngine::Build(const char * module=0x00000000, asIOutputStream * out=0x00570f50)  Line 188	C++
Lands.exe!CSScripting::InitAngelScript()  Line 196 + 0x1c	C++
Lands.exe!CSScripting::Reload()  Line 76	C++
Lands.exe!Refresh()  Line 146	C++
Lands.exe!main()  Line 83	C++
Lands.exe!mainCRTStartup()  Line 259 + 0x19	C
kernel32.dll!7c816d4f() 	
ntdll.dll!7c915b4f() 	
kernel32.dll!7c8399f3() 	

0

Share this post


Link to post
Share on other sites
You've discovered a situation where the compiler allocates a temporary variable to hold an object but doesn't release again as it should. This may make the script function use more stack memory than it really needs, but otherwise the release version should not have any problem.

Would it be possible for you to narrow down your script in order to find what kind of statement it is that causes the assert failure? I would very much like to fix this bug, but without an example that reproduces it I would only be fumbling in the dark.

Oh, if you have a need to use the debug version, but can't wait for the bug fix you could just comment out this assert statement.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by Desdemona
v1.9.0

What I am wondering is what sort of things might be causing this assert to occur:

*** Source Snippet Removed ***


I encountered the same when I used ternary '?' operator with bstr-s (see my another post).

Cheers,
RCL
0

Share this post


Link to post
Share on other sites
Ok, thanks for the information. I applied the patch to the CompileCondition method, but asserts were still failing. I started to get the following assert: "Assertion failed: n < destructors.GetLength(), file d:\code\angelscript_1_9_0\source\as_bytecode.cpp, line 316" while in GenerateExceptionHandler.

I had a little over a dozen script files, so I stripped it down to the bare minimum to run and went from there. It turns out the problem was with the ?: operator after all.

This does not work:


void toggle_option(Data* pPlayer, string mode, string enable, string disable)
{
bool cur = pPlayer->TestFlag(mode, "true");

pPlayer->SetAttributeBase(mode, (cur ? "false" : "true"));
sendto(pPlayer, "\x1B[0;37m" + (cur ? disable : enable) + "\r\n");
}



I changed it so it didn't use the ?: operator and it worked:

void toggle_option(Data* pPlayer, string mode, string enable, string disable)
{
if (pPlayer->TestFlag(mode, "true"))
{
pPlayer->SetAttributeBase(mode, "false");
sendto(pPlayer, "\x1B[0;37m" + disable + "\r\n");
}
else
{
pPlayer->SetAttributeBase(mode, "true");
sendto(pPlayer, "\x1B[0;37m" + enable + "\r\n");
}
}


0

Share this post


Link to post
Share on other sites
I'm sorry for not fixing this one quickly. I didn't have time before now to look at the problem.

I've been able to reproduce the error in my test_framework and it looks like the problem really isn't with the ternary operator :? after all. At least not only with it.

The following test case also fails with the same assertion:


// AngelScript
string a;
void Test(string strA)
{
a = strA;
}


Hopefully I'll have the fix ready in a few hours.

0

Share this post


Link to post
Share on other sites
I believe I've fixed the bug you discovered with the latest WIP. Would you mind verifying if that is the case?

Thanks,
Andreas
0

Share this post


Link to post
Share on other sites
Actually, I'm not sure. I had a complete brain shutdown and testeded it without even installing WIP1. ;) For some reason, it worked when I tried it; odd. I just compiled my project /w WIP1 but it is failing to allocate the script engine at the moment. Strange...
0

Share this post


Link to post
Share on other sites
Ok, all is good now. Apparently my app didnt appriciate me compiling AS using the Multithreaded DLL runtime library. Had to use the Multithreaded runtime library to get it to work. The ?: operator seems to be working, but I'll keep trying to break it...
0

Share this post


Link to post
Share on other sites
hehe [smile]

I'm glad it is fixed. I'm not sure which of the changes it was that corrected the problem though, but I suppose it doesn't matter.
0

Share this post


Link to post
Share on other sites
Ok, I have my head on straight now. Ignore those other posts. :) I seemed to forgot what my own problem was: running in debug mode without assertions killing my app. Well, when I tested the stuff earlier, I was running in release mode (duh).

I tried stuff out in debug mode; oh boy.

1. The original problem still exists:

//Assertion failed: n < destructors.GetLength(), file d:\code\angelscript_1_9_1_wip1\source\as_bytecode.cpp, line 420
bool cur = this->TestFlag(mode, "true");
this->SetAttributeBase(mode, cur ? "false" : "true");
send(cur ? disable : enable);
// Both functions expect string params





2. I've had to remove every instance of ?: from my scripts to stop the assertions from tripping. Here is an example of what used to work, but doesnt anymore:

//Assertion failed: !bc || bc->GetLastCode() == BC_SET4, file d:\code\angelscript_1_9_1_wip1\source\as_compiler.cpp, line 1945
Data* pExit = refid != 0 ? Dataset[refid] : 0;
// refid is uint
// Dataset[refid] returns Data*





3. A new problem which I still don't understand:

for (iterator i = users.Begin(); i != users.End(); i.Next())
{
//Assertion failed: from->isConstant || from->dataType.IsPrimitive(), file d:\code\angelscript_1_9_1_wip1\source\as_compiler.cpp, line 1810
TX.Set("user", i.Value());

user_channel = get_integer_base(i.Value(), "broadcast");

if (user_channel == channel && user_channel != 0)
send("txt_broadcast_join_notify", i.Value(), this);
else if (user_channel == oldchannel && user_channel != 0)
send("txt_broadcast_join_left", i.Value(), this);
}
// TX is a global property
// i.Value() returns Data*






Oddly enough, if I change the above to the following, it compiles ok:


for (iterator i = users.Begin(); i != users.End(); i.Next())
{
TX.Set("user", 0);

user_channel = get_integer_base(i.Value(), "broadcast");

if (user_channel == channel && user_channel != 0)
send("txt_broadcast_join_notify", i.Value(), this);
else if (user_channel == oldchannel && user_channel != 0)
send("txt_broadcast_join_left", i.Value(), this);
}






This works too:


for (iterator i = users.Begin(); i != users.End(); i.Next())
{
Data* temp = i.Value();
TX.Set("user", temp);

user_channel = get_integer_base(i.Value(), "broadcast");

if (user_channel == channel && user_channel != 0)
send("txt_broadcast_join_notify", i.Value(), this);
else if (user_channel == oldchannel && user_channel != 0)
send("txt_broadcast_join_left", i.Value(), this);
}






Strange indeed...
0

Share this post


Link to post
Share on other sites
Very strange indeed.

Ok, at least I have something to go on. I'll try to reproduce the problems exactly as you write them.

Do you register any behaviours for the Data type? It shouldn't really make a difference since you're only using a pointer to the type, but I might have made an error.
0

Share this post


Link to post
Share on other sites
I'm closing in on the problems:

1. These are the test cases that I've identified to have problems
 
// This compiles, but it fails to release the memory
string a = true ? "true" : "false";
SetAttrib(a);

// This gives an assert failure in GenerateExceptionHandler()
SetAttrib(true ? "true" : "false");

// This gives an assert failure in GenerateExceptionHandler()string f = "false", t = "true";
SetAttrib(true ? f : t);


2. I've confirmed the bug

3. I'm not able to reproduce this problem. Could you tell me how you registered the methods TX.Set() and i.Value(). I need to know the parameters you sent to RegisterObjectMethod() for these two.

The first two problems should be fixed soon. I'll need your help before I can fix the third one.
0

Share this post


Link to post
Share on other sites
The problems I am experiencing only creep up during debug builds.

Users cannot create variables of by CStringTransform in the scripts. Instead, they share one global instance (TX):


pEngine->RegisterObjectType("CStringTransform", 0, asOBJ_CLASS);
pEngine->RegisterObjectMethod("CStringTransform", "void Clear()", asMETHOD(CStringTransform, Clear), asCALL_THISCALL);
pEngine->RegisterObjectMethod("CStringTransform", "void Set(const string& tag, Data* pData)", asMETHODP(CStringTransform, Set, (const string&, CData*)), asCALL_THISCALL);
pEngine->RegisterObjectMethod("CStringTransform", "void Set(const string& tag, const string& value)", asMETHODP(CStringTransform, Set, (const string&, const string&)), asCALL_THISCALL);
pEngine->RegisterObjectMethod("CStringTransform", "void Set(const string& tag, int i)", asMETHODP(CStringTransform, Set, (const string&, int)), asCALL_THISCALL);
pEngine->RegisterObjectMethod("CStringTransform", "void Set(const string& tag, float f)", asMETHODP(CStringTransform, Set, (const string&, float)), asCALL_THISCALL);
pEngine->RegisterObjectMethod("CStringTransform", "string Transform(const string& buffer)", asMETHOD(CStringTransform, Transform), asCALL_THISCALL);
m_pEngine->RegisterGlobalProperty("CStringTransform TX", &m_Transform);



This bunch is messy, but here is the iterator:


pEngine->RegisterObjectBehaviour("list", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(list_ctor), asCALL_CDECL_OBJLAST);
pEngine->RegisterObjectBehaviour("list", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(list_dtor), asCALL_CDECL_OBJLAST);
pEngine->RegisterObjectMethod("list", "int Size()", asMETHOD(list<CData*>, size), asCALL_THISCALL);
pEngine->RegisterObjectMethod("list", "void Filter(const string& type)", asFUNCTION(list_filter), asCALL_CDECL_OBJLAST);
pEngine->RegisterObjectMethod("list", "void Clear()", asMETHOD(list<CData*>, clear), asCALL_THISCALL);
pEngine->RegisterObjectMethod("list", "iterator Erase(iterator i)", asMETHODPR(list<CData*>, erase, (list<CData*>::iterator), list<CData*>::iterator), asCALL_THISCALL);
pEngine->RegisterObjectMethod("list", "iterator Begin()", asMETHODPR(list<CData*>, begin, (), list<CData*>::iterator), asCALL_THISCALL);
pEngine->RegisterObjectMethod("list", "iterator End()", asMETHODPR(list<CData*>, end, (), list<CData*>::iterator), asCALL_THISCALL);
pEngine->RegisterObjectMethod("iterator", "Data* Value()", asFUNCTION(iterator_deref), asCALL_CDECL_OBJLAST);
pEngine->RegisterObjectMethod("iterator", "iterator& Next()", asFUNCTION(iterator_next), asCALL_CDECL_OBJLAST);
pEngine->RegisterObjectMethod("iterator", "iterator& Prev()", asFUNCTION(iterator_previous), asCALL_CDECL_OBJLAST);
pEngine->RegisterObjectBehaviour("iterator", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(iterator_ctor), asCALL_CDECL_OBJLAST);
pEngine->RegisterObjectBehaviour("iterator", asBEHAVE_ASSIGNMENT, "iterator& f(const iterator&)", asFUNCTION(iterator_assign_iterator), asCALL_CDECL_OBJLAST);
pEngine->RegisterObjectBehaviour(0, asBEHAVE_EQUAL, "bool f(const iterator&, const iterator&)", asFUNCTION(iterator_equal_iterator), asCALL_CDECL);
pEngine->RegisterObjectBehaviour(0, asBEHAVE_NOTEQUAL, "bool f(const iterator&, const iterator&)", asFUNCTION(iterator_not_equal_iterator), asCALL_CDECL);



And here are the glue functions:


void iterator_ctor(list<CData*>::iterator *pthis)
{
new(pthis)list<CData*>::iterator();
}

list<CData*>::iterator& iterator_assign_iterator(const list<CData*>::iterator &copy, list<CData*>::iterator *pthis)
{
return *pthis = copy;
}

CData* iterator_deref(list<CData*>::iterator* pthis)
{
return **pthis;
}

list<CData*>::iterator& iterator_next(list<CData*>::iterator* pthis)
{
(*pthis)++;
return *pthis;
}

list<CData*>::iterator& iterator_previous(list<CData*>::iterator* pthis)
{
(*pthis)--;
return *pthis;
}

bool iterator_equal_iterator(const list<CData*>::iterator& l, const list<CData*>::iterator& r)
{
return l == r;
}

bool iterator_not_equal_iterator(const list<CData*>::iterator& l, const list<CData*>::iterator& r)
{
return l != r;
}



0

Share this post


Link to post
Share on other sites
fyi, I actually have my current project posted at:

http://members.gamedev.net/ajwright/lands/downloads/landsdev7.zip

Although, I am using VS.NET 2003. If you are using VS6 then I don't think this will compile (differences in the STLs).
0

Share this post


Link to post
Share on other sites
I believe the first two problems have been fixed.

Replace the implementation for the asCCompiler::CompileCondition()


void asCCompiler::CompileCondition(asCScriptNode *expr, asCByteCode *bc, sTypeInfo *type)
{
sTypeInfo ctype, rtype, ltype;

// Compile the conditional expression
asCScriptNode *cexpr = expr->firstChild;
if( cexpr->next )
{
asCByteCode ebc;
CompileExpression(cexpr, &ebc, &ctype);
PrepareOperand(&ctype, &ebc, cexpr);
if( ctype.dataType != asCDataType(ttBool, true, false) )
Error(TXT_EXPR_MUST_BE_BOOL, cexpr);

int afterLabel = nextLabel++;
int elseLabel = nextLabel++;

ebc.InstrINT(BC_JZ, elseLabel);

asCByteCode lebc;
CompileAssignment(cexpr->next, &lebc, &ltype);

// Allocate temporary variable and copy the result to that one
sTypeInfo temp;
temp = ltype;
temp.dataType.isReference = false;
temp.dataType.isReadOnly = false;
int offset = AllocateVariable(temp.dataType, true);
temp.isTemporary = true;
temp.stackOffset = (short)offset;

CompileConstructor(temp.dataType, offset, bc);

bc->AddCode(&ebc);

sTypeInfo rtemp;
rtemp = temp;
rtemp.dataType.isReference = true;

PrepareForAssignment(&rtemp.dataType, &ltype, &lebc, cexpr->next);
lebc.InstrWORD(BC_PSF, offset);
PerformAssignment(&rtemp, &lebc, cexpr->next);
lebc.Pop(ltype.dataType.GetSizeOnStackDWords()); // Pop the original value

// Release the old temporary variable
ReleaseTemporaryVariable(ltype, &lebc);
bc->AddCode(&lebc);

bc->InstrINT(BC_JMP, afterLabel);
bc->Label((short)elseLabel);

asCByteCode rebc;
CompileAssignment(cexpr->next->next, &rebc, &rtype);

// Copy the result to the same temporary variable
PrepareForAssignment(&rtemp.dataType, &rtype, &rebc, cexpr->next);
rebc.InstrWORD(BC_PSF, offset);
PerformAssignment(&rtemp, &rebc, cexpr->next);
rebc.Pop(ltype.dataType.GetSizeOnStackDWords()); // Pop the original value

// Release the old temporary variable
ReleaseTemporaryVariable(rtype, &rebc);
bc->AddCode(&rebc);

bc->Label((short)afterLabel);

bc->InstrWORD(BC_PSF, offset);

// Make sure both expressions have the same type
if( ltype.dataType != rtype.dataType )
Error(TXT_BOTH_MUST_BE_SAME, expr);

// Set the temporary variable as output
*type = rtemp;
}
else
CompileExpression(cexpr, bc, type);
}




Insert the following line in function ImplicitConversionConstant() (as_compiler.cpp, ln: 1874)


from->dataType.isReadOnly = true;


Should look like this:


// Only 0 can be implicitly converted to a pointer
if( to.pointerLevel > 0 )
{
asCDataType temp = asCDataType(ttInt, true, false);
ImplicitConversion(bc, temp, from, node, isExplicit);
if( from->dataType.IsIntegerType() && from->dwordValue == 0 )
{
// Copy all except isReference
from->dataType = to;
from->dataType.isReference = false;
from->dataType.isReadOnly = true;
return;
}
}



I will see if I can reproduce the third problem with the extra information you gave me.

I received VC++.NET 2003 as donation to AngelCode, but I haven't had the time to try it out yet.
0

Share this post


Link to post
Share on other sites
I still can't reproduce the third problem you reported. I created the following test:


#include "utils.h"
#include "stdstr.h"

#define TESTNAME "TestAsserts"

static const char *script1 =
"void Test() \n"
"{ \n"
" Obj i; \n"
" TX.Set(\"user\", i.Value()); \n"
"} \n";

class Obj
{
public:
void *p;
void *Value() {return p;}
void Set(const std::string&, void *) {}
};

static Obj o;

bool TestAsserts()
{
bool fail = false;
int r;

asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);

RegisterStdString(engine);

engine->RegisterObjectType("Data", 0, 0);

engine->RegisterObjectType("Obj", sizeof(Obj), 0);
engine->RegisterObjectMethod("Obj", "Data *Value()", asMETHOD(Obj, Value), asCALL_THISCALL);
engine->RegisterObjectMethod("Obj", "void Set(const string&, Data *)", asMETHOD(Obj, Set), asCALL_THISCALL);
engine->RegisterGlobalProperty("Obj TX", &o);

COutStream out;

engine->AddScriptSection(0, TESTNAME, script1, strlen(script1), 0);
engine->Build(0, &out);

r = engine->ExecuteString(0, "Test()", &out, 0);
if( r < 0 )
{
fail = true;
printf("%s: ExecuteString() failed\n", TESTNAME);
}

engine->Release();

// Success
return fail;
}




Which ought to reproduce the problem as the methods called are registered with the exact same signatures as in your application.

Can you make a test with the above code and see if it causes the same problem with your compiler?
0

Share this post


Link to post
Share on other sites
I posted this test case at http://members.gamedev.net/ajwright/temp/astest1.zip; the project files are .NET, but it should compile under 6.0

Leaving these lines as-is causes the assertion:

r = engine->RegisterObjectType("CStringTransform", 0, asOBJ_CLASS);
r = engine->RegisterObjectMethod("CStringTransform", "void Set(const string& tag, Data* pData)", asMETHODP(CStringTransform, Set, (const string&, CData*)), asCALL_THISCALL);
r = engine->RegisterObjectMethod("CStringTransform", "void Set(const string& tag, const string& value)", asMETHODP(CStringTransform, Set, (const string&, const string&)), asCALL_THISCALL);
//r = engine->RegisterObjectMethod("CStringTransform", "void Set(const string& tag, int i)", asMETHODP(CStringTransform, Set, (const string&, int)), asCALL_THISCALL);



Changing the comment around causing the assertion to go away:

r = engine->RegisterObjectType("CStringTransform", 0, asOBJ_CLASS);
r = engine->RegisterObjectMethod("CStringTransform", "void Set(const string& tag, Data* pData)", asMETHODP(CStringTransform, Set, (const string&, CData*)), asCALL_THISCALL);
//r = engine->RegisterObjectMethod("CStringTransform", "void Set(const string& tag, const string& value)", asMETHODP(CStringTransform, Set, (const string&, const string&)), asCALL_THISCALL);
r = engine->RegisterObjectMethod("CStringTransform", "void Set(const string& tag, int i)", asMETHODP(CStringTransform, Set, (const string&, int)), asCALL_THISCALL);


(It still crashes, but that is to be expected- it is dereferencing an invalid stl iterator.)
0

Share this post


Link to post
Share on other sites
Thanks for taking the time to write the test case. I'm able to reproduce the problem with your code. I'll find a way to fix the bug soon, I hope.
0

Share this post


Link to post
Share on other sites
Ok, the problem was actually the assert itself. So you only have to update it (or remove it if you wish). The correct assert is:


assert(from->isConstant || from->dataType.IsPrimitive() || from->dataType.pointerLevel > 0);


(as_compiler.as, line 1810)


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