jamesjuett / lobster

Interactive Program Visualization Tools
8 stars 3 forks source link

Temporary objects not shown on simulation start #320

Open jamesjuett opened 2 years ago

jamesjuett commented 2 years ago
#include <string>
#include <iostream>
using namespace std;

int foo() {
  return 2;
}

int main() {
  int z = foo();
}

Upon clicking "simulate", the temporary object for the return from foo() does not appear, even after stepping forward. However, if the "restart" button is clicked, it will appear.

iteemhe commented 2 years ago

I have not been able to locate the bug, but I have found the cause of the bug.

In class Observable in observe.ts, it has a member variable called universalObservers. When we first click Simulate button, Lobster does create a runtime function call object and the temporary return variable and send the message to the observer.

However, in sendMessageToObservers, when allocateTemporaryObject in Memory.ts sends the message to observer, the universalObservers is empty, which means that message is sent to nowhere. But once we click Restart, the TemporaryObjectOberserver shows up all of a sudden, so the message of allocation of temporary object can be received correctly. I have trouble in figuring out where does that observer come from.

iteemhe commented 2 years ago

Ok, now I find the issue.

In the ctor of SimpleExerciseLobsterOutlet, it calls stepForward before the sim is set. So, none of listeners is attached. So there is no observes when the message of allocation of temporary object is sent to observers.

Screen Shot 2022-04-03 at 23 49 39

The solution is to switch the order of the while loop and setSimulation.