Page 1 of 1

[r131]Crash at start of game sometimes +EDIT: FULL 64bit FIX

Posted: Thu Jul 10, 2008 6:32
by Agent ME
Sometimes in Doom2, if I start a new game and immediately look down, the game crashes out. Probably around 1 out of 5 times for me.

I'm on Ubuntu 8.04 in 64 bit with the binary compiled to 64 bit. This might be related to this bug, which I'm exhibiting. Seems to only happen in GL mode.

(Ignore everything in crash reports about audio not working - that always happens on my system when I'm listening to music too. Sound works fine otherwise. Apparently my system doesn't support hardware mixing or something.)

Regular crash report. It seems to be cut off at the end, possibly a glitch in g/zdoom. (Taken from file zdoom-crash.log which was generated on crashing.)
Spoiler: Crash Report
Output of GDB when debugged during crash:
Spoiler: Debugging stuff

Posted: Thu Jul 10, 2008 8:21
by Graf Zahl
I hate to say this again: I have no means to debug 64bit apps so I can't look for the problem and fix it.

So now I have the choice of leaving these reports open and do nothing with them or closing them to get them out of the way of real problems.

To sum it up: It is highly unlikely that 64bit GZDoom will work any time soon.

Posted: Thu Jul 17, 2008 0:33
by Agent ME
I think I fixed it - I at least managed to make it not crash any more, but I'm not sure it's completely correct this way.

The crash is caused in line 194 of src/gl/gl_skydome.cpp. Here's the code starting from line 189:

Code: Select all

				if (buffer)
				{
					SkyColors[texno.GetIndex()]=averageColor((unsigned long *) buffer, w * MIN(30, h), false);
					if (h>30)
					{
						SkyColors[texno.GetIndex()+MaxSkyTexture] = averageColor(((unsigned long *) buffer)+(h-30)*w, w * 30, false);
					}
					else SkyColors[texno.GetIndex() + MaxSkyTexture] = SkyColors[texno.GetIndex()];
					delete buffer;
					SkyColors[texno.GetIndex()].a=1;	// mark as processed
				}
I changed line 194 to:

Code: Select all

						SkyColors[texno.GetIndex()+MaxSkyTexture] = averageColor(((unsigned long *) buffer)+30*w, w * 30, false);
It seems that you'd want to advance the buffer by 30*w, not (h-30)*w as before. That seems to prevent the crashing, but I don't think it's completely correct this way. Should the second parameter to averageColor() be w*30 like it is now, w*MIN(30,h) like the above line, or just w*h? I tested a few tries with it as w*h but the game crashed sometimes with it as that.

Posted: Thu Jul 17, 2008 0:58
by Graf Zahl
No, the problem is the 'unsigned long'. On 64 bit GCC that's 8 bytes but everywhere else it's 4 bytes. It should be ZDoom's DWORD instead.

Posted: Thu Jul 17, 2008 6:26
by Agent ME
I went on that advice, went back to the old code, and started replacing occurrences of "long" or "unsigned long" with "DWORD" in places dealing with the GL textures code, and not only did it fix this crash, but it completely fixed the 64-bit rendering errors!

Attached is the patch, I think I set up the patch right.
EDIT: New patch with gl_nodes.cpp fixed, looks right.

Posted: Thu Jul 17, 2008 8:12
by Graf Zahl
Thanks for that. Your help is very much appreciated.

Posted: Thu Jul 17, 2008 8:19
by Graf Zahl
Thanks for that. Your help is very much appreciated.

I also changed gl_nodes.cpp. It would have failed miserably trying to load GL nodes from a GWA file.

Posted: Fri Jul 18, 2008 3:20
by selivanow
@Agent ME:

Wow. That is great. I had an idea that it might be related to 32/64 bit sizes but i just haven't found the time to check it yet. I will apply your patch and check it on my machine.

EDIT: Ok, Agent ME's patch seems to do the trick for me as well.

Posted: Fri Jul 18, 2008 7:37
by Agent ME
I updated the patch to fix gl_nodes.cpp, it seems to look right.