Page 1 of 1

Compiled version won't run

Posted: 27 Jan 2008 16:54
by Hirundo
First of all, my apologies for my newbishness and rather medicore English.

Having played OpenTTD for some time now I wanted to be able to compile my own version of the game. This to be able to make my own small changes, maybe work on a patch, etc. After solving a few minor issues I have now been able to compile openttd using microsoft visual express 2008. However, no matter what I tried, the compiled version won't run, it crashes right after starting up.
Could anyone give me some insight in this?

Re: Compiled version won't run

Posted: 27 Jan 2008 18:15
by DaleStan
Yes. Your debugger.

Re: Compiled version won't run

Posted: 27 Jan 2008 18:47
by LordAzamath
However, no matter what I tried, the compiled version won't run, it crashes right after starting up.
That doesn't say anything about your problem...
One issue I had was that source address had non-stanndard chars in it.. Like รถ. then it said something about utf8 thing.. I compile in linux though so that information isn't adequate I'm afraid :P.

madis

Re: Compiled version won't run

Posted: 27 Jan 2008 19:00
by Hirundo
DaleStan wrote:Yes. Your debugger.
I have downloaded the latest scource code and haven't changed anything, so bad code shouldn't be an issue.

I have attached the crash log, that might help...
Not sure what other files/information I should provide, please just ask for what you need.

Re: Compiled version won't run

Posted: 27 Jan 2008 19:26
by PhilSophus
As I'm running Linux I can only provide some general advice:

Did you put the required files from original TTD into the right place? I think sometimes missing files are not handled gracefully.

From the crash report I only see that it occurred in the openttd executable and not in a DLL. It would definitely help to compile with debugging information and run it under a debugger to find out, where exactly (i.e. in which function and line of code) it crashes.

If you got the source from SVN, providing the SVN revision could also help.

Re: Compiled version won't run

Posted: 28 Jan 2008 01:33
by DaleStan
Swallow wrote:
DaleStan wrote:Yes. Your debugger.
I have downloaded the latest scource code and haven't changed anything, so bad code shouldn't be an issue.
But a bad compiler could be.

Hence, your debugger, to find out what's actually happening, as opposed to what should be happening.

Re: Compiled version won't run

Posted: 28 Jan 2008 16:27
by Hirundo
Excuse me for my ignorance, these are my first steps from php/javascript into the world of serious programming. I have been juggling around with the debugger and the results are below. Now I hope someone is able to decipher them and find the cause of the problems.

EDIT: I'm using the scource r11995

Message
Unhandled exception at 0x00693f82 in openttd.exe: 0xC0000005: Access violation reading location 0x011a932c.

call stack

Code: Select all

>	openttd.exe!DupSprite(unsigned int old_spr=4063, unsigned int new_spr=5863)  Line 268 + 0x6 bytes	C++
 	openttd.exe!ActivateOldShore()  Line 5614	C++
 	openttd.exe!AfterLoadGRFs()  Line 5677	C++
 	openttd.exe!LoadNewGRF(unsigned int load_index=6052, unsigned int file_index=4)  Line 5726	C++
 	openttd.exe!LoadSpriteTables()  Line 249	C++
 	openttd.exe!GfxLoadSprites()  Line 260	C++
 	openttd.exe!GenerateWorld(int mode=1, unsigned int size_x=64, unsigned int size_y=64)  Line 273	C++
 	openttd.exe!ttd_main(int argc=1, char * * argv=0x0012fe00)  Line 571	C++
 	openttd.exe!WinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ * hPrevInstance=0x00000000, 
char * lpCmdLine=0x00151f15, int nCmdShow=1)  Line 1003	C++
 	openttd.exe!__tmainCRTStartup()  Line 263 + 0x2c bytes	C
 	openttd.exe!WinMainCRTStartup()  Line 182	C
 	kernel32.dll!7c816fd7() 	
 	[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]	
 	openttd.exe!MakeNewEditorWorldDone()  Line 735 + 0x10 bytes	C++
 	52990840()	
autos

Code: Select all

		new_spr	5863	unsigned int
-		scnew	0x011c5e80 {ptr=0x00000000 id=0 file_pos=0 ...}	SpriteCache *
		ptr	0x00000000	void *
		id	0	unsigned int
		file_pos	0	unsigned int
		file_slot	0	unsigned short
		lru	0	short
		scnew->file_slot	0	unsigned short
-		scold	0x011a9320 {ptr=??? id=??? file_pos=??? ...}	SpriteCache *
		ptr	CXX0030: Error: expression cannot be evaluated	
		id	CXX0030: Error: expression cannot be evaluated	
		file_pos	CXX0030: Error: expression cannot be evaluated	
		file_slot	CXX0030: Error: expression cannot be evaluated	
		lru	CXX0030: Error: expression cannot be evaluated	
The function which appears the cause the error is this: (spritecache.cpp)

Code: Select all

void DupSprite(SpriteID old_spr, SpriteID new_spr)
{
	SpriteCache *scold = GetSpriteCache(old_spr);
	SpriteCache *scnew = AllocateSpriteCache(new_spr);

	scnew->file_slot = scold->file_slot; <<--error appears here
	scnew->file_pos = scold->file_pos;
	scnew->ptr = NULL;
	scnew->id = scold->id;
}

Re: Compiled version won't run

Posted: 28 Jan 2008 17:23
by PhilSophus
Swallow wrote:EDIT: I'm using the scource r11995
Swallow wrote:

Code: Select all

-		scold	0x011a9320 {ptr=??? id=??? file_pos=??? ...}	SpriteCache *
		ptr	CXX0030: Error: expression cannot be evaluated	
		id	CXX0030: Error: expression cannot be evaluated	
		file_pos	CXX0030: Error: expression cannot be evaluated	
		file_slot	CXX0030: Error: expression cannot be evaluated	
		lru	CXX0030: Error: expression cannot be evaluated	

The function which appears the cause the error is this: (spritecache.cpp)

Code: Select all

void DupSprite(SpriteID old_spr, SpriteID new_spr)
{
	SpriteCache *scold = GetSpriteCache(old_spr);
	SpriteCache *scnew = AllocateSpriteCache(new_spr);

	scnew->file_slot = scold->file_slot; <<--error appears here
	scnew->file_pos = scold->file_pos;
	scnew->ptr = NULL;
	scnew->id = scold->id;
}
So it seems that the scold pointer is pointing to invalid memory (although the address does not look that suspicious). Hmm, I compiled and used r11995 just yesterday under Linux, so I assume that there wasn't a general problem with this release.

Ohh, I think I found the problem: AllocateSpriteCache may reallocate the array, but scold still points to the position before the reallocation.

Swapping the first two lines of the function should fix it. Could you try that? If that fixes it I'll provide a patch and put it into flyspray, when I'm at home.

Re: Compiled version won't run

Posted: 28 Jan 2008 18:30
by glx
crash.txt wrote:Build: norev000 built on Jan 27 2008 13:42:52
The problem is failing version detection (happens only when you build nightly sources). This cause openttd?.grf loading to fail (won't happen once 0.6 branch is created).

For now you can fix it by using svn, or edit src/rev.cpp.in and replace @@REVISION@@ with 11995 (use the value corresponding to the downloaded source)

Re: Compiled version won't run

Posted: 28 Jan 2008 18:39
by PhilSophus
glx wrote:
crash.txt wrote:Build: norev000 built on Jan 27 2008 13:42:52
The problem is failing version detection (happens only when you build nightly sources). This cause openttd?.grf loading to fail (won't happen once 0.6 branch is created).

For now you can fix it by using svn, or edit src/rev.cpp.in and replace @@REVISION@@ with 11995 (use the value corresponding to the downloaded source)
So, if I understand correctly, this is why the bug is triggered for Swallow but not for me. But there still is a bug, or am I mistaken? AllocateSpriteCache can reallocate the memory making scold a dangling pointer.

Anyway, I just posted this to flyspray together with a patch: http://bugs.openttd.org/task/1717

Re: Compiled version won't run

Posted: 28 Jan 2008 21:19
by Hirundo
Using svn did the trick; many thanks :D

Re: Compiled version won't run

Posted: 29 Jan 2008 02:46
by DaleStan
PhilSophus wrote:But there still is a bug, or am I mistaken? AllocateSpriteCache can reallocate the memory making scold a dangling pointer.
Ignoring that class of bug is SOP, as far as I can tell.

I don't know if that's the same bug or not, but I pointed out one of that class some time ago, and the answer was that if the memory was relocated, there were bigger problems than a mere dangling pointer.