(svn r18478) [0.7] -Backport from trunk:

- Fix: When moving a wagon and only the last part of a dual headed engine you could split the dual headed engine over two vehicles (r18462)
- Fix: [Windows] Forgot to load the symbol from SDL.dll (r18439)
- Fix: Do not run the 'jam protection' for vehicles in a depot [FS#3360] (r18428)
- Fix: [Windows] the help window would be too large in some cases [FS#3327] (r18424)
- Fix: Under some circumstances a pointer could be left untouched and then freed. Make sure this does not happen by ensuring it starts out as NULL instead of 'garbage' [FS#3298] (r18418)
This commit is contained in:
rubidium 2009-12-13 00:33:00 +00:00
parent ff67ed58da
commit 0df9eddc9c
7 changed files with 79 additions and 15 deletions

View File

@ -162,6 +162,12 @@ bool AIFileInfo::CheckMethod(const char *name) const
return 0;
}
AIInfo::AIInfo() :
min_loadable_version(0),
use_as_random(false)
{
}
AIInfo::~AIInfo()
{
/* Free all allocated strings */

View File

@ -41,7 +41,7 @@ public:
friend class AIInfo;
friend class AILibrary;
AIFileInfo() : SQ_instance(NULL), main_script(NULL), author(NULL), name(NULL), short_name(NULL), description(NULL), date(NULL), instance_name(NULL), url(NULL) {};
AIFileInfo() : SQ_instance(NULL), main_script(NULL), author(NULL), name(NULL), short_name(NULL), description(NULL), date(NULL), instance_name(NULL), version(0), url(NULL) {};
~AIFileInfo();
/**
@ -123,6 +123,7 @@ class AIInfo : public AIFileInfo {
public:
static const char *GetClassName() { return "AIInfo"; }
AIInfo();
~AIInfo();
/**

View File

@ -57,6 +57,17 @@ BEGIN
END
101 DIALOG DISCARDABLE 0, 0, 600, 400
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "OpenTTD command line help"
FONT 8, "MS Sans Serif"
BEGIN
DEFPUSHBUTTON "&OK",12,274,378,50,14,BS_CENTER
EDITTEXT 11,7,6,583,365,ES_MULTILINE | ES_READONLY | WS_VSCROLL | WS_HSCROLL
END
#ifndef _MAC
/////////////////////////////////////////////////////////////////////////////
//

View File

@ -736,7 +736,7 @@ static Vehicle *EnumCheckRoadVehClose(Vehicle *v, void *data)
return NULL;
}
static Vehicle *RoadVehFindCloseTo(Vehicle *v, int x, int y, Direction dir)
static Vehicle *RoadVehFindCloseTo(Vehicle *v, int x, int y, Direction dir, bool update_blocked_ctr = true)
{
RoadVehFindData rvf;
Vehicle *front = v->First();
@ -765,7 +765,7 @@ static Vehicle *RoadVehFindCloseTo(Vehicle *v, int x, int y, Direction dir)
return NULL;
}
if (++front->u.road.blocked_ctr > 1480) return NULL;
if (update_blocked_ctr && ++front->u.road.blocked_ctr > 1480) return NULL;
return rvf.best;
}
@ -1227,7 +1227,7 @@ static bool RoadVehLeaveDepot(Vehicle *v, bool first)
int y = TileY(v->tile) * TILE_SIZE + (rdp[RVC_DEPOT_START_FRAME].y & 0xF);
if (first) {
if (RoadVehFindCloseTo(v, x, y, v->direction) != NULL) return true;
if (RoadVehFindCloseTo(v, x, y, v->direction, false) != NULL) return true;
VehicleServiceInDepot(v);

View File

@ -61,6 +61,7 @@ static const char sdl_files[] =
M("SDL_SetColorKey")
M("SDL_WM_SetIcon")
M("SDL_MapRGB")
M("SDL_VideoModeOK")
M("")
;
#undef M

View File

@ -965,10 +965,6 @@ static void AddWagonToConsist(Vehicle *v, Vehicle *dest)
*/
static void NormaliseTrainConsist(Vehicle *v)
{
if (IsFreeWagon(v)) return;
assert(IsFrontEngine(v));
for (; v != NULL; v = GetNextVehicle(v)) {
if (!IsMultiheaded(v) || !IsTrainEngine(v)) continue;

View File

@ -937,23 +937,72 @@ void CreateConsole()
#endif
}
/** Temporary pointer to get the help message to the window */
static const char *_help_msg;
/** Callback function to handle the window */
static INT_PTR CALLBACK HelpDialogFunc(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_INITDIALOG: {
char help_msg[8192];
const char *p = _help_msg;
char *q = help_msg;
while (q != lastof(help_msg) && *p != '\0') {
if (*p == '\n') {
*q++ = '\r';
if (q == lastof(help_msg)) {
q[-1] = '\0';
break;
}
}
*q++ = *p++;
}
*q = '\0';
#if defined(UNICODE)
/* We need to put the text in a seperate buffer because the default
* buffer in MB_TO_WIDE might not be large enough (512 chars) */
wchar_t help_msgW[8192];
#endif
SetDlgItemText(wnd, 11, MB_TO_WIDE_BUFFER(help_msg, help_msgW, lengthof(help_msgW)));
SendDlgItemMessage(wnd, 11, WM_SETFONT, (WPARAM)GetStockObject(ANSI_FIXED_FONT), FALSE);
} return TRUE;
case WM_COMMAND:
if (wParam == 12) ExitProcess(0);
return TRUE;
case WM_CLOSE:
ExitProcess(0);
}
return FALSE;
}
void ShowInfo(const char *str)
{
if (_has_console) {
fprintf(stderr, "%s\n", str);
} else {
bool old;
#if defined(UNICODE)
/* We need to put the text in a seperate buffer because the default
* buffer in MB_TO_WIDE might not be large enough (512 chars) */
wchar_t help_msgW[8192];
#endif
ReleaseCapture();
_left_button_clicked = _left_button_down = false;
old = MyShowCursor(true);
if (MessageBox(GetActiveWindow(), MB_TO_WIDE_BUFFER(str, help_msgW, lengthof(help_msgW)), _T("OpenTTD"), MB_ICONINFORMATION | MB_OKCANCEL) == IDCANCEL) {
CreateConsole();
if (strlen(str) > 2048) {
/* The minimum length of the help message is 2048. Other messages sent via
* ShowInfo are much shorter, or so long they need this way of displaying
* them anyway. */
_help_msg = str;
DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(101), NULL, HelpDialogFunc);
} else {
#if defined(UNICODE)
/* We need to put the text in a seperate buffer because the default
* buffer in MB_TO_WIDE might not be large enough (512 chars) */
wchar_t help_msgW[8192];
#endif
if (MessageBox(GetActiveWindow(), MB_TO_WIDE_BUFFER(str, help_msgW, lengthof(help_msgW)), _T("OpenTTD"), MB_ICONINFORMATION | MB_OKCANCEL) == IDCANCEL) {
CreateConsole();
}
}
MyShowCursor(old);
}