Skip to content
This repository was archived by the owner on Apr 17, 2022. It is now read-only.

Game state is not reset after a corrupted savegame file is loaded #981

Closed
wzdev-ci opened this issue Oct 5, 2009 · 28 comments
Closed

Game state is not reset after a corrupted savegame file is loaded #981

wzdev-ci opened this issue Oct 5, 2009 · 28 comments

Comments

@wzdev-ci
Copy link
Contributor

wzdev-ci commented Oct 5, 2009

resolution_fixed type_bug | by anonymous


As is discussed here http://forums.wz2100.net/viewtopic.php?f=4&t=3889

    i-NoD wrote:Just use official 2.2.3 version (will remove asserts). Image
    - Start a new game -> try to save a game with 'savetest ' name -> it will fail -> quit game.
    1. Launch game -> try to load a previously failed 'savetest ' game -> it will fail -> load some normal save -> it should load -> try to load 'savetest ' game -> should give you exactly the reported 2-nd crash (attached a similar dump).
    2. Launch game -> try to load a previously failed 'savetest ' game -> it will fail -> go to skirmish -> try to enter limiter screen -> a crash without a dump file



The reason why that happens is the state machine voodoo. Image
It finds the .gam file and it changes whatever based on that file and then it can not load the other files that it needs and nothing gets reset to virgin state.
Most of the stage init routines were called but no shutdown routines are called so nothing gets cleaned up.
Use --debug all and it shows this.

The easy fix is to pre-screen filenames to not have spaces at the end of them eg "test 1 " Either remove trailing spaces or convert them to "test_1____". For whatever reason physfs chokes on filenames with trailing spaces before the directory specifier ("savegame/test 1 /game.map") in the PHYSFS_openWrite() call.

The more complex fix would be to keep track of each init stage and on fail call the cleanup routine for that stage.

--Kosh


Issue migrated from trac:981 at 2022-04-15 19:50:44 -0700

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Oct 6, 2009

-Kosh- commented


Here is the fix so the delete routine can work correctly.

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Oct 6, 2009

-Kosh- uploaded file deleteFix.patch (13.9 KiB)

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Oct 6, 2009

Per changed status from new to accepted

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Oct 6, 2009

Per set owner to Per

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Oct 6, 2009

Per commented


I'll commit it with two fixes: Using PATH_MAX instead of MAX_PATH (no idea what the latter is - does not exist here), and using sstrcpy() instead of memcpy() for strings (always use this on static destination strings). Note that saving with spaces at the end of filenames works perfectly fine here.

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Oct 6, 2009

Per changed status from accepted to closed

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Oct 6, 2009

Per set resolution to fixed

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Oct 6, 2009

Per commented


(In [8226]) Use temporary variable for manipulating filenames inside savegame function, so that original is not
clobbered on early failure return. Closes #981, patch by forum member Kosh.

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Oct 6, 2009

Per changed status from closed to reopened

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Oct 6, 2009

Per changed resolution from fixed to ``

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Oct 6, 2009

Per changed milestone from 2.3 to unspecified

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Oct 6, 2009

Per commented


I guess this should not be quite closed yet.

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Oct 6, 2009

Zarel commented


What's unclosed about it? The fact that it hasn't been backported to 2.3?

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Oct 6, 2009

-Kosh- commented


Replying to Warzone2100/old-trac-import#981 (comment:5):

What's unclosed about it? The fact that it hasn't been backported to 2.3?

That and the core of the problem is not fixed. If a error pops up someplace in the load routine after it read the .gam file it is not cleaned up correctly.

Here is another patch that correctly does removeWildcards()

All those listed are not supported by windows according to http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx

For the issue that windows people had, the name "stuff 1 " is invalid when it comes to making a directory name "stuff 1 " because of the trailing space(s).
The game made "stuff 1 ".gam (valid) then it tried to make a directory called "stuff 1 " (invalid) and then it failed for everything after that.

With the removeWildcards() patch, if user enters "stuff 1 " it now becomes "stuff_1____". Could have just trimmed the trailing space(s) but I opted for the easier approach. :P

Whoever did removeWildcards() had a bad day it seems since that would have never worked, and it never did.

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Oct 6, 2009

-Kosh- uploaded file wildcardfix.patch (0.9 KiB)

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Oct 6, 2009

-Kosh- commented


I forgot to ask if there was a state diagram someplace floating around ?

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Oct 6, 2009

anonymous commented


Replying to Warzone2100/old-trac-import#981 (comment:6):

Replying to Warzone2100/old-trac-import#981 (comment:5):

What's unclosed about it? The fact that it hasn't been backported to 2.3?

That and the core of the problem is not fixed. If a error pops up someplace in the load routine after it read the .gam file it is not cleaned up correctly.

Here is another patch that correctly does removeWildcards()

All those listed are not supported by windows according to http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx

For the issue that windows people had, the name "stuff 1 " is invalid when it comes to making a directory name "stuff 1 " because of the trailing space(s).
The game made "stuff 1 ".gam (valid) then it tried to make a directory called "stuff 1 " (invalid) and then it failed for everything after that.

With the removeWildcards() patch, if user enters "stuff 1 " it now becomes "stuff_1____". Could have just trimmed the trailing space(s) but I opted for the easier approach. :P

Whoever did removeWildcards() had a bad day it seems since that would have never worked, and it never did.

Odd, it is not showing all the underscores? It shows one underscore like "" but not multiple like "__". I guess more than one underscore is a escape sequence of some type for trac?

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Oct 7, 2009

Zarel commented


...yes, __text__ means text (underline text). After the first time, you probably should've tried preview. Use ``` to escape code, so escaped code becomes escaped code.

Like so:

For the issue that windows people had, the name "stuff 1 " is invalid when it comes to making a directory name "stuff 1 " because of the trailing space(s).
The game made "stuff 1 ".gam (valid) then it tried to make a directory called "stuff 1 " (invalid) and then it failed for everything after that.

With the removeWildcards() patch, if user enters "stuff 1 " it now becomes "stuff_1____". Could have just trimmed the trailing space(s) but I opted for the easier approach. :P

Whoever did removeWildcards() had a bad day it seems since that would have never worked, and it never did.

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Oct 7, 2009

Zarel commented


And, ugh, underscores are ugly. Just get rid of trailing spaces. I will not tolerate underscores in my Warzone. D:

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Oct 7, 2009

Zarel commented


Oh, and, you're wrong about removeWildcards, since you misunderstood how removeWildcards works.

removeWildcards may not have gotten rid of spaces, but it did remove wildcards correctly. Look carefully. What it does is get rid of all characters except alphanumeric characters, and ' ' '-' '+' '!', and replace them with '_'.

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Oct 7, 2009

Zarel commented


Oh, and in your patch, everything after !isalnum(pStr[i]) is redundant. Did you miss the !? And what it does after that?

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Oct 7, 2009

Zarel commented


I've committed a better fix for the trailing spaces in: [8227] and [8228]

Is that all (other than backporting to 2.3)?

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Oct 7, 2009

-Kosh- commented


:o I misread that code.
The deletefix.patch should be in branch/2.2 as well.

I am really confused on what is going to be 2.3, will it be branch/2.2 or is the next version 2.2.4 and is current trunk going to be 2.5 or what?

I do not think this ticket can be closed until someone figures out how to cleanup everything once that .gam file loads and it fails in another part of the loading routine.

p.s why does your trac version not e-mail people when there is a reply?

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Oct 7, 2009

Zarel commented


2.3 is currently branches/2.2. I call it 2.3 to emphasize that the next release of branches/2.2 will be some version of 2.3.

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Apr 22, 2010

Buginator commented


Replying to Warzone2100/old-trac-import#981 (comment:14):

:o I misread that code.
The deletefix.patch should be in branch/2.2 as well.

I am really confused on what is going to be 2.3, will it be branch/2.2 or is the next version 2.2.4 and is current trunk going to be 2.5 or what?

I do not think this ticket can be closed until someone figures out how to cleanup everything once that .gam file loads and it fails in another part of the loading routine.

p.s why does your trac version not e-mail people when there is a reply?

You should be getting a e-mail, if not, then it is a bug.

For the other stuff you mentioned, (a corrupted .gam file), this is on my TODO list, and I am adding myself to the ticket.

@wzdev-ci
Copy link
Contributor Author

vexed changed status from reopened to closed

@wzdev-ci
Copy link
Contributor Author

vexed changed resolution from `` to fixed

@wzdev-ci
Copy link
Contributor Author

vexed commented


Trailing spaces don't cause issues anymore.

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

No branches or pull requests

1 participant