Main Menu

CW3 gets "stuck"

Started by planetfall, July 11, 2014, 04:47:49 AM

Previous topic - Next topic

planetfall

I played a map that I made all the way through normally without any hitches.

However, upon reloading it, the game seems "stuck," for lack of a better term. Packets won't do anything. Ordering units to move sometimes results in them moving and sometimes results in them standing there doing nothing. Animations don't animate. Other things screw up. Attached is a screenshot of a particularly grievous problem with a bomber. Also, the CRPL core in that picture (bottom right) didn't have a health bar showing before reloading - not sure if that's important.

Opening it in the editor and deleting the three CRPL cores on the map "unstuck" the game, but the cores were functioning correctly before the reload. It seems I have to delete all three for the problem to go away, so it's not a problem with just one of the instances. Anyway, if there was an issue with the scripts, it still theoretically shouldn't be possible to put the game into this kind of broken state, right?
Pretty sure I'm supposed to be banned, someone might want to get on that.

Quote from: GoodMorning on December 01, 2016, 05:58:30 PM"Build a ladder to the moon" is simple as a sentence, but actually doing it is not.

Karsten75

Next time try saving and reloading the map again. see if that clears it up. There is an instance of something where I recall that a map could seem stuck and one had to reload it multiple times to get past various pause states that stacked up? I don't recall the specifics - it was a long time back.

knucracker

"Stuck" usually means the game is throwing an exception that causes the game loop to abort prematurely.  This would show up as a message over and over in the game's log and help narrow down the root cause.

planetfall

Actually, there are two slightly different errors (though I don't know whether both apply to this problem - I can't see any time stamps.). After a long run of the same one it periodically switches and goes into a long run of the other.

(Filename:  Line: -1)

InvalidOperationException: Operation is not valid due to the current state of the object
  at System.Collections.Generic.Stack`1[CrplCore+Data].Pop () [0x00000] in <filename unknown>:0
  at CrplCore.ProcessCommands (Boolean start, Boolean final, Boolean gameLoaded, Boolean paused) [0x00000] in <filename unknown>:0
  at CrplCore.GameUpdate (Boolean final, Boolean paused) [0x00000] in <filename unknown>:0
  at CRPLTowerManager.PausedGameUpdate () [0x00000] in <filename unknown>:0
  at GameSpace.Update () [0x00000] in <filename unknown>:0

(Filename:  Line: -1)

InvalidOperationException: Operation is not valid due to the current state of the object
  at System.Collections.Generic.Stack`1[CrplCore+Data].Pop () [0x00000] in <filename unknown>:0
  at CrplCore.ProcessCommands (Boolean start, Boolean final, Boolean gameLoaded, Boolean paused) [0x00000] in <filename unknown>:0
  at CrplCore.GameUpdate (Boolean final, Boolean paused) [0x00000] in <filename unknown>:0
  at UnitManager.GameUpdate () [0x00000] in <filename unknown>:0
  at CRPLTowerManager.GameUpdate () [0x00000] in <filename unknown>:0
  at GameSpace.UnitsUpdate () [0x00000] in <filename unknown>:0
  at GameSpace.GameUpdate () [0x00000] in <filename unknown>:0
  at GameSpace.Update () [0x00000] in <filename unknown>:0
Pretty sure I'm supposed to be banned, someone might want to get on that.

Quote from: GoodMorning on December 01, 2016, 05:58:30 PM"Build a ladder to the moon" is simple as a sentence, but actually doing it is not.

knucracker

Does the mission you attached in the top post reproduce the problem for you when you load it up? 
Exception wise, one of them seems to have to do with a core that has a script set to operated while paused.  Something is trying to pop from the stack while the CRPL stack is empty most likely. 

planetfall

Yes, it does. And the script in the save does operate while paused.

Question... if a script is paused with the Delay command with data on the stack, does the stack persist when the script resumes? What if the game is saved while it's delayed, are the stack, script position, and delay timer stored in the save?
Pretty sure I'm supposed to be banned, someone might want to get on that.

Quote from: GoodMorning on December 01, 2016, 05:58:30 PM"Build a ladder to the moon" is simple as a sentence, but actually doing it is not.

planetfall

While I'm not normally one to bump threads or be impatient, this seems like a pretty major bug being ignored (unless V is working on it and just not saying anything, in which case I apologize). If I have the answers to the questions in my previous post, I can at least try to fix the script that's causing the issue.
Pretty sure I'm supposed to be banned, someone might want to get on that.

Quote from: GoodMorning on December 01, 2016, 05:58:30 PM"Build a ladder to the moon" is simple as a sentence, but actually doing it is not.

knucracker

There was a flurry of support and other things that came it all at once and I lost track of this (plus I'm in the research phase on the next project and that eats up 90% of my thought).  So yeah, I had forgotten about this and thanks for bumping it.

So I can reproduce the issue when I load your map.  I can also tell it is coming from the "loop" CRPL command.  I'll have to inspect things closer to see what is going on....

knucracker

Ok, so there are a few places in the game code I can make things more robust so the game doesn't throw exceptions.  I've done that, but they only cover up the problem and make it "invisible".  They also aren't something I want to spend a couple days mastering and distributing new builds for.  They will go into the source tree, but only show up at some time in the future when there is more to release.

Now, for the source of the problem.  The exception you are getting is from HomingLauncher.crpl and is from this "loop" command:

...
I 2000 mod eq0 if
1 delay
endif
#This is to keep from hitting the opcode limit.
loop


The combination of a Do/Loop with a nested Delay and an Awake function... that turns out to be poison.  A Delay stops execution and next frame will resume execution.  If you save the game during a delay, the game saves the loop stack, and where execution should resume.  When the game gets loaded, the problem is that the "Awake" function gets called and that processes the script.  Part of this processing clears the loop stack.  After Awake is processed, execution resumes after where the Delay left off.  When the Loop command is executed it tries to look at the loop stack and low and behold finds it is empty.

Six months ago I'd spend several days fixing and testing this in the CrplCore code.  But... it is harder to justify spending the time on it at this stage.  I'm already deep into the research phase of a new title and mothballing that for a couple days wouldn't be wise right now.  I may come back to this in a few weeks, but for now I'd like to suggest working around the issue.

The way to work around it should be to not do that Delay inside a do/loop.  You might be able to get away with restructuring so that you break out of the do loop and do a delay outside of a loop.  If you try to put that delay in a safe place where nothing else will happen after it, then the problems should go away.  You might also just be able to get rid of that Delay completely and replace it with a Break statement....

planetfall

What if I put the awake function in a separate script? OperateWhilePaused is per core, not per script, correct?
Pretty sure I'm supposed to be banned, someone might want to get on that.

Quote from: GoodMorning on December 01, 2016, 05:58:30 PM"Build a ladder to the moon" is simple as a sentence, but actually doing it is not.

knucracker

You can do that too... in theory :)  The Delay makes me nervous because it allows a script to be saved in the "middle" of execution.  But based on what I looked at for this problem, not having any functions that execute on a script prior to any of the normal execution passes (things like Awake) should bypass this problem.