Skip to content

Commit c5d2856

Browse files
committed
[FIX] Stack overflow in inputcomponent
1 parent a576079 commit c5d2856

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

src/specialComponents/Input.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,23 @@ nts::InputComponent::~InputComponent()
2121

2222
void nts::InputComponent::simulate(std::size_t tick)
2323
{
24-
(void)tick;
25-
if (_pins[0].lock() == nullptr) {
24+
if (_lastTick == tick)
25+
return;
26+
_lastTick = tick;
27+
28+
if (_pins[0].lock() == nullptr)
2629
this->setState(nts::UNDEFINED);
27-
}
2830
else {
29-
this->setState(_pins[0].lock()->compute(tick));
31+
auto linkedComponent = _pins[0].lock();
32+
linkedComponent->simulate(tick);
33+
this->setState(linkedComponent->getState());
3034
}
3135
}
3236

3337
nts::Tristate nts::InputComponent::compute(std::size_t tick)
3438
{
35-
this->simulate(tick);
39+
if (_lastTick != tick)
40+
this->simulate(tick);
3641
return this->getState();
3742
}
3843

0 commit comments

Comments
 (0)