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:
T *value = nullptr;
bool replaceIfNull;
public:
explicit ReplacingRefreshDeferrerAccumulator(bool replaceIfNull = true)
: replaceIfNull(replaceIfNull) {}
~ReplacingRefreshDeferrerAccumulator() override
{
delete value;
@ -39,6 +43,9 @@ public:
protected:
void accumulate(RefreshDeferrerParams params) override
{
if (!replaceIfNull && !params) {
return;
}
delete value;
value = static_cast<T *>(params);
}

View File

@ -33,14 +33,13 @@ protected:
void closeEvent(QCloseEvent *event) override;
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);
connect(deferrer, &RefreshDeferrer::refreshNow, this, [refreshNowFunc](const RefreshDeferrerParamsResult paramsResult) {
printf("got refresh now!\n");
auto *offset = static_cast<const ParamResult *>(paramsResult);
refreshNowFunc(offset);
auto *result = static_cast<const ParamResult *>(paramsResult);
refreshNowFunc(result);
});
return deferrer;
}

View File

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