From 8dc76b0044c947a926cbb594f77c0a2b83f25304 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Thu, 3 Mar 2016 19:14:10 +0000 Subject: [PATCH 1/2] Be more strict checking for space in program pool in mgmt actions. --- src/tracerestrict.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/tracerestrict.cpp b/src/tracerestrict.cpp index 763dd5edc2..8913a7af6f 100644 --- a/src/tracerestrict.cpp +++ b/src/tracerestrict.cpp @@ -1003,6 +1003,10 @@ CommandCost CmdProgramSignalTraceRestrictProgMgmt(TileIndex tile, DoCommandFlag } } + if (type != TRDCT_PROG_RESET && !TraceRestrictProgram::CanAllocateItem()) { + return CMD_ERROR; + } + if (!(flags & DC_EXEC)) { return CommandCost(); } From 4d94470d08173cfda819a288241dc5d3aeafe0b2 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Tue, 8 Mar 2016 19:20:55 +0000 Subject: [PATCH 2/2] Update all tracerestrict windows when a restricted signal is removed. This fixes share counts in any open windows sharing the same program not being updated. --- src/tracerestrict.cpp | 9 +++++++-- src/tracerestrict.h | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/tracerestrict.cpp b/src/tracerestrict.cpp index 8913a7af6f..1697404551 100644 --- a/src/tracerestrict.cpp +++ b/src/tracerestrict.cpp @@ -647,8 +647,9 @@ void TraceRestrictCreateProgramMapping(TraceRestrictRefId ref, TraceRestrictProg /** * Remove a program mapping + * @return true if a mapping was actually removed */ -void TraceRestrictRemoveProgramMapping(TraceRestrictRefId ref) +bool TraceRestrictRemoveProgramMapping(TraceRestrictRefId ref) { TraceRestrictMapping::iterator iter = _tracerestrictprogram_mapping.find(ref); if (iter != _tracerestrictprogram_mapping.end()) { @@ -678,6 +679,9 @@ void TraceRestrictRemoveProgramMapping(TraceRestrictRefId ref) } } } + return true; + } else { + return false; } } @@ -717,8 +721,9 @@ TraceRestrictProgram *GetTraceRestrictProgram(TraceRestrictRefId ref, bool creat void TraceRestrictNotifySignalRemoval(TileIndex tile, Track track) { TraceRestrictRefId ref = MakeTraceRestrictRefId(tile, track); - TraceRestrictRemoveProgramMapping(ref); + bool removed = TraceRestrictRemoveProgramMapping(ref); DeleteWindowById(WC_TRACE_RESTRICT, ref); + if (removed) InvalidateWindowClassesData(WC_TRACE_RESTRICT); } /** diff --git a/src/tracerestrict.h b/src/tracerestrict.h index c62f21fe33..2409025408 100644 --- a/src/tracerestrict.h +++ b/src/tracerestrict.h @@ -513,7 +513,7 @@ static inline Track GetTraceRestrictRefIdTrack(TraceRestrictRefId ref) } void TraceRestrictCreateProgramMapping(TraceRestrictRefId ref, TraceRestrictProgram *prog); -void TraceRestrictRemoveProgramMapping(TraceRestrictRefId ref); +bool TraceRestrictRemoveProgramMapping(TraceRestrictRefId ref); TraceRestrictProgram *GetTraceRestrictProgram(TraceRestrictRefId ref, bool create_new);