diff --git a/src/drivers/human/human.cpp b/src/drivers/human/human.cpp index ba5965d03..7d15a2d25 100644 --- a/src/drivers/human/human.cpp +++ b/src/drivers/human/human.cpp @@ -95,6 +95,7 @@ static int lastReadKeyState[GFUIK_MAX+1]; static tKeyInfo keyInfo[GFUIK_MAX+1]; static bool firstTime = false; +static int resumeIndex = 0; static tdble lastKeyUpdate = -10.0; void *PrefHdle = NULL; @@ -146,6 +147,8 @@ shutdown(const int index) GfuiKeyEventRegisterCurrent(0); firstTime = false; }//if firstTime + + resumeIndex = 0; }//shutdown @@ -614,8 +617,13 @@ resumerace(int index, tCarElt* car, tSituation *s) HmReadPrefs(index); // Setup Keyboard map (key code => index of the associated command in keyInfo / lastReadKeyState). - keyIndex = 0; - mapKeys.clear(); + if (index > resumeIndex) { + // must be first time after start/resume (index counts down) + GfOut("Clearing Keyboard map (index %d)\n", index); + keyIndex = 0; + mapKeys.clear(); + } + resumeIndex = index; for (int i = 0; i < NbCmdControl; i++) { diff --git a/src/drivers/human/pref.cpp b/src/drivers/human/pref.cpp index 6eca72b02..50ce95672 100644 --- a/src/drivers/human/pref.cpp +++ b/src/drivers/human/pref.cpp @@ -85,7 +85,11 @@ HmReadPrefs(const int index) const int idx = index - 1; tControlCmd *cmdCtrl; - cmdCtrl = HCtx[idx]->cmdControl = (tControlCmd *) calloc (NbCmdControl, sizeof (tControlCmd)); + if (HCtx[idx]->cmdControl == NULL) { + GfOut("malloc control array index %d:\n", index); + HCtx[idx]->cmdControl = (tControlCmd *) calloc (NbCmdControl, sizeof (tControlCmd)); + } + cmdCtrl = HCtx[idx]->cmdControl; memcpy(cmdCtrl, CmdControlRef, NbCmdControl * sizeof (tControlCmd)); sprintf(sstring, "%s%s", GfLocalDir(), HM_PREF_FILE); @@ -128,7 +132,7 @@ HmReadPrefs(const int index) defaultSettings = controlList[i].settings; /* Command Settings */ - GfOut("Command settings :\n"); + GfOut("Command settings for index %d:\n", index); for (int cmd = 0; cmd < NbCmdControl; cmd++) { prm = GfctrlGetNameByRef(cmdCtrl[cmd].type, cmdCtrl[cmd].val);