Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix turret explosion crash #73

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Kappa971
Copy link

@Kappa971 Kappa971 commented May 8, 2024

I'm having a pretty bad crash in the "Trenches" level when I destroy a turret with the revolver.
This doesn't happen with the precompiled v2.2.1. The latest working build is with the commit: 71f14cd
The commit af636f5 makes impossible to load the savegame. The savegame crash was fixed in commit 4ab826e but here there is the crash mentioned above with turret explosions.

This is the savegame file: savegame.zip
Load it, aim with the revolver by pressing the PAD0 and shoot the small white tank positioned behind the turret, the game will crash with the latest build compiled from master branch.

Let me start by saying that I'm not a programmer, I only have very basic knowledge of C++, I looked for a simple solution that would allow me to complete the game. For the moment I have not experienced any other crashes.
The crash seems to be caused by these two pieces of code in output.cpp:

...

void ProcessObjectMeshVertices(MESH_DATA* mesh)
{

                ...

		if (current_item)
		{
			if (!(room[current_item->room_number].flags & ROOM_UNDERWATER) && camera.underwater)
			{
				cR = (cR * water_color_R) >> 8;
				cG = (cG * water_color_G) >> 8;
				cB = (cB * water_color_B) >> 8;
			}
		}

                ...

}

...
...

void phd_PutPolygonSkyMesh(short* objptr, long clipstatus)
{

        ...

	current_item = 0;
        ProcessObjectMeshVertices(mesh);

        ...

}

...

Anyway, I managed to prevent the game from crashing after the turret explosion moving current_item = 0; before loading a level instead of output.cpp, as mentioned in the PR.

It seems to work with this other solution too:
file.cpp

...

long S_LoadLevelFile(long num)
{
	char name[80];
	current_item = 0;    //HERE

	Log(2, "S_LoadLevelFile");
	strcpy(name, &gfFilenameWad[gfFilenameOffset[num]]);
	strcat(name, ".TR4");
	LevelLoadingThread.active = 1;
	LevelLoadingThread.ended = 0;
	LevelLoadingThread.handle = _beginthreadex(0, 0, &LoadLevel, name, 0, (unsigned int*)&LevelLoadingThread.address);
	while (LevelLoadingThread.active);
	return 1;
}

...

As already said, I'm not a programmer, so if this isn't the ideal solution for you, you can close the PR, but since no one is interested in it for the moment, I think this is better than nothing 😅.

I attach the compiled executable for testing (the "crocodile underwater death animation" fix by TokyoSU is also included): tomb4.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant