Ludeon Forums

RimWorld => Bugs => Topic started by: shmooe on October 07, 2014, 08:59:21 PM

Title: Fire bug crashing game causing bad lag and insane amounts of errors a second
Post by: shmooe on October 07, 2014, 08:59:21 PM
so im in yr 3, at yr 2 1/2 I noticed the fire was flashing on and off and my frames dropped a little. Now it has gotten much worse i get 4fps or crash. I turned on the dev tools to look at the log and this is what i found. Now if i dont focus the fire my fps goes back to 60. also when my guys fight the fire they walk in it, even though the pic looks like no fire between fire, it flashes on and off and burns them. Makes it very hard to put out and lags me bad. any fix for this. its not stopping! the file is to big to post

[attachment deleted by admin: too old]
Title: Re: Fire bug crashing game causing bad lag and insane amounts of errors a second
Post by: SpazMan777 on October 11, 2014, 09:34:10 AM
I can confirm this occurs and even have video confirmation of it happening: http://www.twitch.tv/spazman777/c/5275480 (http://www.twitch.tv/spazman777/c/5275480)

It occurred in November of Year 2, coinciding with the OP's timeframe.  The fire started from an incendiary mortar.  I, however, heavily modify my game so I did not submit a bug report; but I came across this topic and wanted to contribute any info I had to help isolate the issue.

Also the OP did not specify, but in my case, I'm running 0.7.583 on Windows.
Title: Re: Fire bug crashing game causing bad lag and insane amounts of errors a second
Post by: shmooe on October 11, 2014, 07:32:45 PM
Quote from: SpazMan777 on October 11, 2014, 09:34:10 AM
I can confirm this occurs and even have video confirmation of it happening: http://www.twitch.tv/spazman777/c/5275480 (http://www.twitch.tv/spazman777/c/5275480)

It occurred in November of Year 2, coinciding with the OP's timeframe.  The fire started from an incendiary mortar.  I, however, heavily modify my game so I did not submit a bug report; but I came across this topic and wanted to contribute any info I had to help isolate the issue.

YES this is what mygame is doing to just like the video but i didnt mod anything in the game at all
Also the OP did not specify, but in my case, I'm running 0.7.583 on Windows.
Title: Re: Fire bug crashing game causing bad lag and insane amounts of errors a second
Post by: Kulverstukass on October 15, 2014, 10:59:45 AM
Here is the same, encountered twice for a sort of long-last colonies, right now it is day 333-334 when the same problem with fire occurs.
Looks like Tynan already noted that at bugtracker himself, but even if it's make game unplayable it is marked as "minor".
https://ludeon.com/mantis/view.php?id=1218
Title: Re: Fire bug crashing game causing bad lag and insane amounts of errors a second
Post by: Summoned on October 25, 2014, 02:59:39 PM
It feels almost like a memory leak or something. Once I get to year 3 or 4, the fire bug always activates and the game becomes nearly impossible to play.

The problem is that because it only happens really late in the game the bug is hard to reproduce.
Title: Re: Fire bug crashing game causing bad lag and insane amounts of errors a second
Post by: bullwinkle on October 27, 2014, 12:28:48 PM
i get this exact bug around the end of year 2 also, actually just made a post about performance issues which i thought was the problem.
Title: Re: Fire bug crashing game causing bad lag and insane amounts of errors a second
Post by: Gizmoandsmudge on October 27, 2014, 09:41:50 PM
I can also confirm this bug, get it at 3+ years gone by. Sucks as you can't really continue playing due to the lag. All my hard work D':
Title: Re: Fire bug crashing game causing bad lag and insane amounts of errors a second
Post by: Devdisigdu on October 28, 2014, 08:22:32 AM
I got this in May year 2 in my most recent colony, the second colony I've 'lost' to this bug. I've not had it crash on me, but I do get low FPS and error spam in the log, same as posted above.
Title: Re: Fire bug crashing game causing bad lag and insane amounts of errors a second
Post by: StorymasterQ on October 28, 2014, 08:42:16 PM
"After a few years, the game crashed into a RimWorld." An aggravating, yet somewhat lore-fitting end.
Title: Re: Fire bug crashing game causing bad lag and insane amounts of errors a second
Post by: Wex on October 28, 2014, 11:10:17 PM
I found a workaround. Create a new world, new map, new game.
Make fire happen. Save. Quit.
Reload original game. Fire bug should be gone.
Title: Re: Fire bug crashing game causing bad lag and insane amounts of errors a second
Post by: Devdisigdu on October 29, 2014, 12:24:46 PM
Tried that just now, Wex. I can't reproduce your workaround.

I created a new world, then a new colony. Used dev mode to spawn fire in via lightning. Saved the game then quit back to main menu. Loaded up the save with the fire issue, still getting the low FPS and a log filled with errors.
Title: Re: Fire bug crashing game causing bad lag and insane amounts of errors a second
Post by: skullywag on October 29, 2014, 01:05:16 PM
Has anyone got a save they can upload (preferably vanilla no mods) would help troubleshoot or find workarounds.
Title: Re: Fire bug crashing game causing bad lag and insane amounts of errors a second
Post by: tom_kazansky on October 29, 2014, 02:36:09 PM
Here the full local folder.

(edb installed,not needed to load)

QuoteRestrictions: 6 per post, maximum total size 600KB, maximum individual size 300KB
I'm sorry.

[attachment deleted by admin: too old]
Title: Re: Fire bug crashing game causing bad lag and insane amounts of errors a second
Post by: Wex on October 29, 2014, 08:42:51 PM
Quote from: Devdisigdu on October 29, 2014, 12:24:46 PM
Tried that just now, Wex. I can't reproduce your workaround.

I created a new world, then a new colony. Used dev mode to spawn fire in via lightning. Saved the game then quit back to main menu. Loaded up the save with the fire issue, still getting the low FPS and a log filled with errors.
You got it wrong. Quit the game. Back to desktop.
Title: Re: Fire bug crashing game causing bad lag and insane amounts of errors a second
Post by: Gizmoandsmudge on November 02, 2014, 09:51:50 PM
Don't know about anybody else, but the error spamming stops on year 4. It's just year 3 for me, though after the fire stopped glitching everything else pretty much broke (Trade menu spits out errors and doesn't open, Colonists break sit and do nothing etc.)
Title: Re: Fire bug crashing game causing bad lag and insane amounts of errors a second
Post by: VStraken on November 05, 2014, 04:07:57 PM
I've gotten this problem on one of my latest games, and it's only about 3/4 of the way into the 2nd year that it's happened; last time it happened rather late into the 3rd year. I've also tried the workaround posted, but to no avail.
Title: Re: Fire bug crashing game causing bad lag and insane amounts of errors a second
Post by: MyNameIsChaz on November 06, 2014, 03:59:11 AM
I've had the same problem. It started around year 2-3 and would severely lag the game. I played through it however, and eventually it just stopped happening (around year 6-7) and my fire is back to normal. I play with only one mod- Prepare Carefully.
Title: Re: Fire bug crashing game causing bad lag and insane amounts of errors a second
Post by: SmallEquine on November 06, 2014, 11:09:30 PM
Can confirm that the fire bug happens every time it gets to year 3. Its a shame because thats around the time my colony gets big but i cant play it because the fps drop every time there's a mechtoid raid. i really hope there's a fix.
Title: Re: Fire bug crashing game causing bad lag and insane amounts of errors a second
Post by: qwe85 on March 28, 2015, 01:20:46 PM
The problem is still unsolved
Mantis Id 0001423
https://ludeon.com/mantis/view.php?id=1423

My worlds + output_log.txt
https://www.dropbox.com/s/pt32llfdqcko3fh/RimWorld.zip?dl=0
Load the save FireBug which have the problem.


/ qwe85
Title: Re: Fire bug crashing game causing bad lag and insane amounts of errors a second
Post by: Tynan on March 29, 2015, 11:53:41 PM
thanks greatly for the info everyone.

This bug has been hard to find but with the savegames and year-3 reports I may be able to solve it.

https://ludeon.com/mantis/view.php?id=1648
Title: Re: Fire bug crashing game causing bad lag and insane amounts of errors a second
Post by: qwe85 on March 30, 2015, 05:18:48 AM
Hi,

I have found a way to reproduce it.
There is a slow and a quick way.

Slow.
1. Create new world
2. Create new colony on the new world
3. Start alot of fires
4. Time accelerate until almost everything is burned down.
5. Save Colony
6. Repeat step 2-5 until the error occur

Quick.
1. Create new world
2. Edit new world setting nextThingId to 5420000 (Remember to save)
3. Create new colony on the new world
4. Start modest amount of fires
5. Time accelerate until the error occur.

It seems the magic number is 5.492.076.
When a fire with Id 5492076 or higher starts the error occurs


/ qwe85
Title: Re: Fire bug crashing game causing bad lag and insane amounts of errors a second
Post by: skullywag on March 30, 2015, 07:39:54 AM
Tynan what exactly is all the math for at the top of the drawworker in graphic_flicker. Its using thingIDs and based on the above comment it sounds very plausible Its in the right area.
Title: Re: Fire bug crashing game causing bad lag and insane amounts of errors a second
Post by: Tynan on March 30, 2015, 04:00:48 PM
Quote from: qwe85 on March 30, 2015, 05:18:48 AM
Hi,

I have found a way to reproduce it.
There is a slow and a quick way.

Slow.
1. Create new world
2. Create new colony on the new world
3. Start alot of fires
4. Time accelerate until almost everything is burned down.
5. Save Colony
6. Repeat step 2-5 until the error occur

Quick.
1. Create new world
2. Edit new world setting nextThingId to 5420000 (Remember to save)
3. Create new colony on the new world
4. Start modest amount of fires
5. Time accelerate until the error occur.

It seems the magic number is 5.492.076.
When a fire with Id 5492076 or higher starts the error occurs


/ qwe85

That's amazing!

Thank you!
Title: Re: Fire bug crashing game causing bad lag and insane amounts of errors a second
Post by: Tynan on March 30, 2015, 04:07:11 PM
Yes it makes perfect sense now. The problem is in here.

int adjustedTickCount = Find.TickManager.TicksGame;
int tickIndex = 0;
int frameIndex = 0;
Fire fire = null;
float fireSize = 1;
if( thing != null )
{
adjustedTickCount += thing.thingIDNumber*391; //Offset

tickIndex = adjustedTickCount / BaseTicksPerFrameChange;

//Determine frame graphic from indices in random order
//I wish I could make this never repeat frames
frameIndex = (tickIndex ^ (thing.thingIDNumber*391)) % subGraphics.Length;

fire = thing as Fire;
if( fire != null )
fireSize = fire.fireSize;
}

Graphic frameGraphic = subGraphics[frameIndex];


//Determine draw scale
float drawSize = Mathf.Min(fireSize / 1.2f, 1.2f);

//Determine draw pos
//Choose a random offset by selecting a random square from the radial pattern
Vector3 curOffset = GenRadial.RadialPattern[tickIndex % GenRadial.RadialPattern.Length].ToVector3() / GenRadial.MaxRadialPatternRadius;
curOffset *= MaxOffset;
Vector3 drawPos = loc + (curOffset * fireSize);

//Draw
Vector3 scaler = new Vector3( drawSize, 1, drawSize);
Matrix4x4 matrix = new Matrix4x4();
matrix.SetTRS( drawPos, Quaternion.identity, scaler);

Graphics.DrawMesh(MeshPool.plane10, matrix, frameGraphic.MatSingle, 0);



This code chooses a frame for the fire to draw functionally. As in it doesn't use any stored state, it just determines which animation frame to draw based on the current tick and the id of the fire.

The problem is this: adjustedTickCount += thing.thingIDNumber*391; //Offset

It turns out that multiplying by 391 is a bit of a problem. Because the numbers can get so big that they go out of the integer range!

The failure id (5492076) times 391 is 2147401716. Which is very close to a familiar number: the max value of a signed 32-bit integer is 2,147,483,647.

Oddly this is the first time I've run into an integer wrapping error. I'm sure it won't be the last. Thanks again qwe.
Title: Re: Fire bug crashing game causing bad lag and insane amounts of errors a second
Post by: Tynan on March 30, 2015, 05:00:50 PM
Locking as the bug is fixed. PM me if it comes back, thanks.