Fix DisassemblyWidget refreshing

This commit is contained in:
Florian Märkl 2019-01-13 14:59:08 +01:00 committed by xarkes
parent d651a0d8be
commit 9ef971263f
3 changed files with 14 additions and 11 deletions

View File

@ -29,8 +29,12 @@ class ReplacingRefreshDeferrerAccumulator: public RefreshDeferrerAccumulator
{ {
private: private:
T *value = nullptr; T *value = nullptr;
bool replaceIfNull;
public: public:
explicit ReplacingRefreshDeferrerAccumulator(bool replaceIfNull = true)
: replaceIfNull(replaceIfNull) {}
~ReplacingRefreshDeferrerAccumulator() override ~ReplacingRefreshDeferrerAccumulator() override
{ {
delete value; delete value;
@ -39,6 +43,9 @@ public:
protected: protected:
void accumulate(RefreshDeferrerParams params) override void accumulate(RefreshDeferrerParams params) override
{ {
if (!replaceIfNull && !params) {
return;
}
delete value; delete value;
value = static_cast<T *>(params); value = static_cast<T *>(params);
} }

View File

@ -33,14 +33,13 @@ protected:
void closeEvent(QCloseEvent *event) override; void closeEvent(QCloseEvent *event) override;
template<class ParamResult, typename Func> template<class ParamResult, typename Func>
RefreshDeferrer *createReplacingRefreshDeferrer(Func refreshNowFunc) RefreshDeferrer *createReplacingRefreshDeferrer(bool replaceIfNull, Func refreshNowFunc)
{ {
auto *deferrer = new RefreshDeferrer(new ReplacingRefreshDeferrerAccumulator<ParamResult>(), this); auto *deferrer = new RefreshDeferrer(new ReplacingRefreshDeferrerAccumulator<ParamResult>(replaceIfNull), this);
deferrer->registerFor(this); deferrer->registerFor(this);
connect(deferrer, &RefreshDeferrer::refreshNow, this, [refreshNowFunc](const RefreshDeferrerParamsResult paramsResult) { connect(deferrer, &RefreshDeferrer::refreshNow, this, [refreshNowFunc](const RefreshDeferrerParamsResult paramsResult) {
printf("got refresh now!\n"); auto *result = static_cast<const ParamResult *>(paramsResult);
auto *offset = static_cast<const ParamResult *>(paramsResult); refreshNowFunc(result);
refreshNowFunc(offset);
}); });
return deferrer; return deferrer;
} }

View File

@ -62,9 +62,8 @@ DisassemblyWidget::DisassemblyWidget(MainWindow *main, QAction *action)
setupFonts(); setupFonts();
setupColors(); setupColors();
disasmRefresh = createReplacingRefreshDeferrer<RVA>([this](const RVA *offset) { disasmRefresh = createReplacingRefreshDeferrer<RVA>(false, [this](const RVA *offset) {
printf("got refresh now!\n"); refreshDisasm(offset ? *offset : RVA_INVALID);
refreshDisasm(*offset);
}); });
maxLines = 0; maxLines = 0;
@ -199,11 +198,9 @@ QWidget *DisassemblyWidget::getTextWidget()
void DisassemblyWidget::refreshDisasm(RVA offset) void DisassemblyWidget::refreshDisasm(RVA offset)
{ {
if(!disasmRefresh->attemptRefresh(new RVA(offset))) { if(!disasmRefresh->attemptRefresh(offset == RVA_INVALID ? nullptr : new RVA(offset))) {
printf("we tried to refresh, but shouldn't yet.\n");
return; return;
} }
printf("ok, actually refreshing now!\n");
if (offset != RVA_INVALID) { if (offset != RVA_INVALID) {
topOffset = offset; topOffset = offset;