Jump to content

  • Log In with Google      Sign In   
  • Create Account


- - - - -

the basic tutorial crashes in 2.26.1


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 darthvolvo   Members   -  Reputation: 107

Like
1Likes
Like

Posted 04 March 2013 - 03:32 PM

Following the basic tutorial in the latest release, the program segfaults.

This is on 64-bit linux.

Valgrind output:
==4057== Memcheck, a memory error detector
==4057== Copyright © 2002-2012, and GNU GPL'd, by Julian Seward et al.
==4057== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==4057== Command: ./foo
==4057==
==4057== Invalid read of size 8
==4057==    at 0x4EC68C8: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&) (in /usr/lib/libstdc++.so.6.0.9)
==4057==    by 0x4075E0: CopyConstructString(std::string const&, std::string*) (scriptstdstring.cpp:125)
==4057==    by 0x449A5F: X64_CallFunction(unsigned long const*, int, unsigned long (*)(), unsigned long&, bool) (as_callfunc_x64_gcc.cpp:142)
==4057==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==4057==
==4057==
==4057== Process terminating with default action of signal 11 (SIGSEGV)
==4057==  Access not within mapped region at address 0x0
==4057==    at 0x4EC68C8: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&) (in /usr/lib/libstdc++.so.6.0.9)
==4057==    by 0x4075E0: CopyConstructString(std::string const&, std::string*) (scriptstdstring.cpp:125)
==4057==    by 0x449A5F: X64_CallFunction(unsigned long const*, int, unsigned long (*)(), unsigned long&, bool) (as_callfunc_x64_gcc.cpp:142)
==4057==  If you believe this happened as a result of a stack
==4057==  overflow in your program's main thread (unlikely but
==4057==  possible), you can try to increase the size of the
==4057==  main thread stack using the --main-stacksize= flag.
==4057==  The main thread stack size used in this run was 8388608.
==4057==
==4057== HEAP SUMMARY:
==4057==     in use at exit: 67,922 bytes in 366 blocks
==4057==   total heap usage: 766 allocs, 400 frees, 90,995 bytes allocated
==4057==
==4057== LEAK SUMMARY:
==4057==    definitely lost: 0 bytes in 0 blocks
==4057==    indirectly lost: 0 bytes in 0 blocks
==4057==      possibly lost: 35 bytes in 1 blocks
==4057==    still reachable: 67,887 bytes in 365 blocks
==4057==         suppressed: 0 bytes in 0 blocks
==4057== Rerun with --leak-check=full to see details of leaked memory
==4057==
==4057== For counts of detected and suppressed errors, rerun with: -v
==4057== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 5 from 5)
Code attached.

Sponsor:

#2 darthvolvo   Members   -  Reputation: 107

Like
0Likes
Like

Posted 04 March 2013 - 03:34 PM

Uploading didn't work, so pasting here.
#include "angelscript.h"
#include "scriptstdstring.h"
#include 
#include 

using namespace std;

void cb(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 string &in) {
	printf("%s\n", in.c_str());
}

const char mscript[] = "void main() { print(\"I believe!\"); }";

int main() {

	asIScriptEngine *ng = asCreateScriptEngine(ANGELSCRIPT_VERSION);

	int r;

	r = ng->SetMessageCallback(asFUNCTION(cb), 0, asCALL_CDECL);
	if (r < 0) printf("error %d\n", r);

	RegisterStdString(ng);

	r = ng->RegisterGlobalFunction("void print(const string &in)", asFUNCTION(print),
		asCALL_CDECL);
	if (r < 0) printf("error %d\n", r);

	// build
	asIScriptModule *mod = ng->GetModule("moi", asGM_ALWAYS_CREATE);
	mod->AddScriptSection("joo", mscript);

	r = mod->Build();
	if (r < 0) printf("error %d\n", r);

	// execute
	asIScriptFunction *f = mod->GetFunctionByDecl("void main()");
	if (!f)
		return 1;

	asIScriptContext *ctx = ng->CreateContext();
	ctx->Prepare(f);
	r = ctx->Execute();
	if (r < 0) printf("error %d\n", r);

	ng->Release();

	return 0;
}
BTW, I had to disable javascript to be able to post at all, the editor didn't let me to write anything in the text field. It refused to take focus.

#3 Andreas Jonsson   Moderators   -  Reputation: 3263

Like
0Likes
Like

Posted 04 March 2013 - 03:53 PM

Thanks I'll look into it.

 

 

About the editor not working. You probably need to clear your browser cache. The last time GDNet upgraded the forum software I had a similar problem. Clearing the cache resolved it.


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

#4 Andreas Jonsson   Moderators   -  Reputation: 3263

Like
0Likes
Like

Posted 04 March 2013 - 05:03 PM

Hmm. I couldn't reproduce this problem. 

 

I compiled the code you provided and ran it with valgrind as you did, but no problem was detected:

 

 

 
==17210== Memcheck, a memory error detector
==17210== Copyright © 2002-2012, and GNU GPL'd, by Julian Seward et al.
==17210== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==17210== Command: ./tutorial
==17210==
I believe!
==17210==
==17210== HEAP SUMMARY:
==17210==     in use at exit: 67,922 bytes in 366 blocks
==17210==   total heap usage: 766 allocs, 400 frees, 90,995 bytes allocated
==17210==
==17210== LEAK SUMMARY:
==17210==    definitely lost: 0 bytes in 0 blocks
==17210==    indirectly lost: 0 bytes in 0 blocks
==17210==      possibly lost: 35 bytes in 1 blocks
==17210==    still reachable: 67,887 bytes in 365 blocks
==17210==         suppressed: 0 bytes in 0 blocks
==17210== Rerun with --leak-check=full to see details of leaked memory
==17210==
==17210== For counts of detected and suppressed errors, rerun with: -v
==17210== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)

 

Observe, the memory leak that was detected is because you didn't release the context before existing. 


Edited by Andreas Jonsson, 04 March 2013 - 05:07 PM.

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

#5 darthvolvo   Members   -  Reputation: 107

Like
0Likes
Like

Posted 05 March 2013 - 10:28 AM

Re leak:

I understand that a context cannot exist without the engine. It'd be logical for destroying the engine to also destroy the contexts, other frameworks I've used follow this principle. But this is not the main issue.

Re issue:

It's accessing a NULL pointer at that line. I'm not familiar with manually calling functions via asm, or even how to know which calling convention I should tell angelscript to use. Please advise.

#6 darthvolvo   Members   -  Reputation: 107

Like
0Likes
Like

Posted 05 March 2013 - 10:37 AM

The manual calling evidently confuses gdb, but it's also causing the bug here - a NULL reference. That's not supposed to be possible in normal C++. Function in question:
static void CopyConstructString(const string &other, string *thisPointer)
{
        new(thisPointer) string(other);
}
gdb output breaking on it:
Breakpoint 1, CopyConstructString (other=@0x0, thisPointer=0xf64438) at scriptstdstring.cpp:125
125             new(thisPointer) string(other);
(gdb) bt full
#0  CopyConstructString (other=@0x0, thisPointer=0xf64438) at scriptstdstring.cpp:125
No locals.
#1  0x0000000000451874 in endstack ()
No symbol table info available.
#2  0x00007fff313eac00 in ?? ()
No symbol table info available.
#3  0x0000000000f52010 in ?? ()
No symbol table info available.
#4  0x00007fff313eac00 in ?? ()
No symbol table info available.
#5  0x00007fff313eab98 in ?? ()
No symbol table info available.
#6  0x0000000000434a8e in asCString::Assign ()
No symbol table info available.
#7  0x00007f00313eac80 in ?? ()
No symbol table info available.
#8  0x0000000000000001 in ?? ()
No symbol table info available.
#9  0x0000000000000000 in ?? ()
No symbol table info available.


#7 Andreas Jonsson   Moderators   -  Reputation: 3263

Like
0Likes
Like

Posted 05 March 2013 - 12:53 PM

I understand that you're somehow getting a null pointer to the CopyConstructString, and it may very well be a bug in AngelScript. However, I ran the exact same code you posted on Linux 64bit with valgrind and couldn't reproduce the problem.

 

Did you get this problem with the code you posted, or do you have a different code? Would it be possible to attach the code you have for reproducing the problem, including the makefile you use? 

 

 

Also, did you upgrade from a previous version of AngelScript? Or is this the first time you've used it? If you did upgrade, can you do a clean build, i.e. remove all .obj files and then recompile everything?


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

#8 darthvolvo   Members   -  Reputation: 107

Like
0Likes
Like

Posted 06 March 2013 - 05:11 AM

It's the exact code I use (with the exception of mangled includes, that was done by the GD forum software). This is the first time I'm using Angelscript, as I'm evaluating which scripting language to use in a project.

It was most certainly a clean build, and I've done various builds since with make clean in between. All show the issue.

I build it with "g++ -o foo foo.cpp scriptstdstring.cpp -Os -s -Wall -Wextra -langelscript".

#9 Andreas Jonsson   Moderators   -  Reputation: 3263

Like
0Likes
Like

Posted 06 March 2013 - 08:43 AM

Ok. It might be the optimization options that is causing the problem. I'll give it a try.


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

#10 Andreas Jonsson   Moderators   -  Reputation: 3263

Like
0Likes
Like

Posted 06 March 2013 - 10:15 AM

The problem is definitely related to the compiler optimizations. Compiling the library and application with any optimization flag except -O0 (no optimization) causes problems with 64bit. On 32bit, i.e compiling with -m32, all optimization modes work though.

 

I'll fix the problem with optimizations on 64bit as soon as I can. In the meantime, please turn off the optimizations when you're testing. 


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

#11 Andreas Jonsson   Moderators   -  Reputation: 3263

Like
0Likes
Like

Posted 08 March 2013 - 06:09 PM

I found the problem. The compiler was optimizing away a local variable in X64_CallFunction because it didn't see that it was updated by the assembler code. 

 

I've checked in the fix in revision 1588. 


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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS