F. Troubleshooting
Something in your game behaves oddly, and you'd like to know why. This appendix starts from what you see, grouped by where the trouble shows, and points you to the section that explains the cause and the fix. It doesn't restate them: each chapter's Common Mistakes section, or the section named, has the whole story.
Related: Glossary · MVT on One Page · The Eight Principles
If what you see isn't here, find the part of MVT it touches in Appendix A, and read the chapter its rule links to.
F.1 The Model
| Symptom | Where to look |
|---|---|
| Resizing the screen, or drawing the game at a different scale, changes how it plays. | 4.10.1 Pixels in a model |
| The second game starts with odd numbers, or a test passes alone but fails after another. | 4.10.3 Models that share state through the module |
| You can't test a child model without building the whole game around it. | 4.10.4 A child that references its sibling |
| Adding touch controls, or a second key for the same thing, means changing the model. | 4.10.5 A model named after its controls |
| A child model sits still, though the game runs. | 4.10.6 A child that's never updated |
| You're not sure whether a model may import a data table, a helper or a constant. | 29.6 Common Misreadings |
| A view shows the wrong amount of a transition, or two progress values are both 0, and the model doesn't say which phase is running. | 6.6.1 A progress for each phase |
| The model exposes how long a phase has lasted, but the model's own code never reads it. | 6.6.2 A clock kept only for a view |
| The game can't start a level, or finish a transition, without a view, and tests need a stand-in view. | 6.6.3 A view that calls the model to move on |
| You can't decide whether a piece of state belongs in a model or a view. | 11.6 When Is Presentation State Really Domain State? |
| You're tempted to add a game manager that decides which screen to show. | 26.7 Common Misreadings |
F.2 Time
| Symptom | Where to look |
|---|---|
| Pausing the game doesn't pause something, tests fail now and then, or a bug won't happen the same way twice. | 4.10.2 A timer on the wall clock |
| After you switch back to the game's tab, objects have passed through walls, or a whole phase has been skipped. | 5.8.2 An uncapped deltaMs |
| While the game is paused, a fade finishes, or a light keeps blinking. | 5.8.3 A paused game that keeps moving |
| An animation runs at different speeds on different screens, or carries on through a pause. | 11.8.1 An animation that ignores the game's speed |
| The game plays differently at different frame rates, such as a timer or phase that runs slow on a slow phone, or a fast object that passes a wall only at 30 frames a second. | 6.5 Steps of Different Sizes |
GSAP tweens are added, but the objects don't move, though update() is called every tick. | E.7.1 Forgetting to advance the timeline |
| A model that uses GSAP moves on in real time, whatever the ticker does. | E.7.2 Auto-playing a GSAP timeline |
A set() after a GSAP tween never happens, and the object stops for good. | E.7.3 Zero-duration GSAP tweens |
F.3 Views and Bindings
| Symptom | Where to look |
|---|---|
| A sprite runs too fast on a fast screen, keeps moving while the game is paused, or ends up somewhere other than the model's position. | 7.10.1 A sprite that runs ahead of the model |
| The game behaves differently depending on which views exist, or the order they refresh in. | 7.10.2 A game that depends on which views exist |
| Two views disagree for a frame. | 5.8.1 A view that changes a model during a tick |
| An animation runs at double speed, or a view deep in the tree never moves. | 13.6.3 A view that runs twice, or never |
Code that hooks Pixi's onRender runs a different number of times from the ticks, or not at all in a test. | 7.9.1 Why not Pixi's onRender? |
| A view is right at first, then shows a stale value after a restart or a new level. | 8.9.1 A view that shows a stale value after a restart |
A view's relay binding, such as onShoot, means the wrong thing in the next game. | 8.9.2 A relay binding that means the wrong thing in the next game |
A view quietly falls back to 0 or '', and hides a wiring mistake. | 8.9.3 A view that hides a wiring mistake |
| A reusable view works in one game, but can't be used in another, or tested without a real model. | 8.9.4 A reusable view that only works with one model |
| The game behaves differently, or breaks, when a view is removed or replaced. | 11.8.4 A game that changes when a view is removed |
| A view looks right in the game, but is missing pieces in a test. | 11.8.2 A view that's missing pieces in a test |
| Something flashes into the wrong state for one frame as its view appears. | 11.8.3 A view that flashes the wrong state as it appears |
| A text field overwrites what the player is typing. | 11.4 Controls That Are Both Output and Input |
The model receives input for a change that the game made itself, such as a scroll or popstate event after the view wrote to the page. | 11.4 Controls That Are Both Output and Input |
| In JSX, a property is stuck at its first value, such as a sprite left where the ship started. | 12.13.1 A property stuck at its first value |
| A part of a JSX view never appears, or never goes. | 12.13.2 A part of the view that never appears, or never goes |
| A sprite flickers between two sizes, or settles on the wrong one. | 12.13.4 Two attributes that write the same state |
| A JSX view throws as it's built, with a message naming an attribute. | 12.13.5 A view that throws as it's built, naming an attribute |
| A middle view's bindings include a value, such as a palette, that it only passes on to its children. | 13.6.1 A middle view that passes on a value it never uses |
| Your view tree has a view for every model, and the backdrop and the transitions don't have an obvious home. | 13.6.2 A view tree that copies the model tree |
A keyboard handler keeps running after its view is gone, or a 'destroyed' listener never runs. | 7.8 Releasing a View's Resources |
| You've made a view model for a single fade, and the fade is now harder to find. | 18.7.1 A view model whose update does one thing |
| Effects in several sub-views start together, then drift apart. | 18.7.2 Effects that start together, then drift apart |
| One-off setup, such as placing particles, repeats every frame, and the particles pile up. | 18.7.3 Particles that pile up |
| Effects stop matching the game when it pauses or slows. | 18.7.4 Effects that stop matching the game when it pauses |
| A view model can't be tested without a sprite. | 18.7.5 A view model you can't test without a sprite |
| Your view has a lot of logic, and you wonder whether that breaks MVT's rules. | 26.7 Common Misreadings |
F.4 Noticing Changes
| Symptom | Where to look |
|---|---|
| A sound sometimes doesn't play, or plays a frame late. | 9.9.1 A sound that sometimes doesn't play |
| The opening tune never plays, or the first phase's texture is never set. | 9.9.2 An opening tune that never plays |
| A reaction, watcher or computed value throws when it reads its getter. | 9.9.3 A tool that throws as it reads its getter |
| A view misses a thing on a grid that changes its kind. | 9.9.4 A change on a grid that goes unseen |
| The second shot in a row doesn't play a sound. | 9.9.5 A second shot that doesn't play a sound |
| Two shots fired in the same tick play one sound. | 9.6.2 Several occurrences in one tick |
| One moment plays two sounds, because it changed two values. | 9.6.4 Two changes, one moment |
| A watcher reports the wrong values, or throws in development. | 9.9.6 A watcher that reports the wrong values |
| A getter reads as a change on every frame, though the value hasn't changed. | 9.5.1 A change is a difference between two reads |
| A reaction keeps watching the old objects after the model replaces them. | 9.5.4 A tool's getters are fixed when it's made |
| You wonder whether remembering last frame's value is a second copy of the state. | 27.6 Common Misreadings |
F.5 Lists
| Symptom | Where to look |
|---|---|
| A slot shows its first item's look or data after its item changes. | 14.8.1 A slot that shows its first item after the item changes |
| Every getter in an item view checks whether its slot is empty. | 14.8.2 Checks for an empty slot in every getter |
| Out-of-range errors, or the wrong item, in a slot's view. | 14.8.3 Out-of-range errors, or the wrong item, in a slot's view |
| A list keeps showing a collection the model has replaced. | 14.8.5 A list that keeps showing a replaced collection |
A <Match> throws, as the view is built or as it first refreshes. | 14.8.7 A <Match> that throws |
A <Switch> hides every branch during a new phase. | 14.5 Showing One of Several: <Switch> |
| Items jump instead of sliding, or a new item takes over the old one's fade. | 19.7.1 Items that jump instead of sliding |
| A removed item vanishes at once, instead of animating out. | 19.7.2 A removed item that vanishes at once |
| A new item slides in from where the last one stood, or arrives half faded. | 19.7.3 A new item that slides in from the last one's place |
| Mid-drag, the drag jumps to another card, or drops the wrong one. | 19.7.4 A drag that jumps to another card |
| Removed items never leave, a slot list fills up, or it throws in development. | 4.10.6 A child that's never updated |
F.6 Sound
| Symptom | Where to look |
|---|---|
| A model's tests need a sound chip, or making a thumbnail makes a noise. | 20.8.1 A model's tests that need a sound chip |
| A sound starts again every frame. | 20.2.1 Play on a change, never on a state |
| A sound plays in the game, but not when the view is refreshed without an update. | 20.8.2 A sound that plays in the game, but not in a refresh alone |
| The game's first sound or song doesn't play. | 9.9.2 An opening tune that never plays |
| Sounds sent as events are missed while a view is made, or the game is paused. | 20.8.3 Sounds sent as events go missing |
| A list item's sound never plays when the item is removed. | 20.3 Sound for a Collection |
| A sound plays when a new item fills a list's slot. | 20.3 Sound for a Collection |
| A jingle is cut short by the next phase's song. | 20.5 Music |
| A repeating sound ignores pausing, or drifts from the game. | 20.4 Sounds That Repeat |
| The music, and sounds already playing, carry on while the game is paused. | 20.6 The Clock That Sound Plays On |
F.7 Tests
| Symptom | Where to look |
|---|---|
| A test fails, or passes, with the model barely moved. | 15.9.1 A test that passes with the model barely moved |
| In a test, a phase the model should have reached is never reached. | 15.9.2 A phase the test never reaches |
A test fails with expected 2.0000000000000004 to be 2. | 15.9.3 A position that's off by a hair |
| A test breaks when a rule moves from one child model to another, though the game plays the same. | 15.9.4 A parent's test that breaks when a rule moves |
| A view test finds the defaults, not the state it set up. | 16.6.1 A view test that finds the defaults |
| A view test passes, though the view never follows a change. | 16.6.2 A test that passes though the view never follows a change |
A test checks visible, but the player can't see the object. | 16.6.3 A visible object that the player can't see |
| A visual test fails now and then with a small difference, and passes when it runs again. | 17.7.1 An image that differs on every run |
| A test of a fading or counting view captures the first frame of its transition every time. | 17.7.2 A transition that's always at its first frame |
| Every change to the game fails a dozen visual tests. | 17.7.3 A dozen whole-screen tests failing at once |
| A bug has become a reference image. | 17.7.4 A bug in a reference image |
| You're adding a method only so a test can reach it, or mocking everything a component uses. | 33.6 Common Misreadings |
F.8 Performance
| Symptom | Where to look |
|---|---|
| The game stutters now and then, without an obvious cause. | 23.3 Garbage Turns Into Pauses |
| A view makes new text, or redraws a whole grid, every frame, for a value that rarely changes. | 7.10.3 Slow work on every frame |
| A JSX getter builds a new string every frame. | 12.13.3 A getter that builds a string every frame |
An items getter builds a new array every frame. | 14.8.4 An items getter that builds a new array |
| Taking a subtree out of the tree to stop it refreshing makes things slower, not faster. | 14.8.6 A hidden subtree that makes things slower |
| Hidden views still take time every tick. | 24.5.4 Hidden views that still take time every tick |
| An index loop still makes a closure every tick. | 24.5.3 An index loop that still makes a closure every tick |
| A setup function or a level loader, rewritten with index loops, is harder to read, and isn't any faster. | 24.5.1 Setup code rewritten for speed it doesn't need |
| You rewrote code because it looked slow, and the game doesn't run any faster. | 24.5.2 Code rewritten for speed that doesn't run any faster |
| A page of HTML cards makes frames late when a view measures them in its refresh step. | 21.2 Why Not Measure in the Refresh Step? |
| Two approaches, timed side by side, produce results that change with their order. | D.2 One Approach per Process |
| A reactive approach looks instant in a benchmark. | D.5 Check That the Work Happens |
| A profile puts almost all the time on one outer function. | D.8 Read Profiles With Inlining in Mind |
| You're not sure whether performance matters for your game at all. | 23.5 When Performance Needs Attention |