Debugging
If our code panics, we want informative error messages to appear in thedeveloper console.
Our comes with an optional, enabled-by-default dependencyon that is configured inwasm-game-of-life/src/utils.rs
. All we need to do is install the hook in aninitialization function or common code path. We can call it inside theUniverse::new
constructor in wasm-game-of-life/src/lib.rs
:
Let's use the console.log
function via the web-sys
crate to add somelogging about each cell in our function.
For ergonomics, we'll wrap the console.log
function up in a println!
-stylemacro:
Now, we can start logging messages to the console by inserting calls to log
inRust code. For example, to log each cell's state, live neighbors count, and nextstate, we could modify like this:
This provides us with a convenient checkpoint for inspecting logged messages,and comparing the currently rendered frame to the previous one.
Add logging to the
tick
function that records the row and column of eachcell that transitioned states from live to dead or vice versa.