diff --git a/src/tracerestrict.cpp b/src/tracerestrict.cpp index caeb935acc..9100f1a8ae 100644 --- a/src/tracerestrict.cpp +++ b/src/tracerestrict.cpp @@ -1002,17 +1002,17 @@ CommandCost CmdProgramSignalTraceRestrictProgMgmt(TileIndex tile, DoCommandFlag switch (type) { case TRDCT_PROG_COPY: { TraceRestrictRemoveProgramMapping(self); - TraceRestrictProgram *prog = GetTraceRestrictProgram(self, true); - if (!prog) { - // allocation failed - return CMD_ERROR; - } TraceRestrictProgram *source_prog = GetTraceRestrictProgram(source, false); - if (source_prog) { + if (source_prog && !source_prog->items.empty()) { + TraceRestrictProgram *prog = GetTraceRestrictProgram(self, true); + if (!prog) { + // allocation failed + return CMD_ERROR; + } prog->items = source_prog->items; // copy + prog->Validate(); } - prog->Validate(); break; }