Your solution looks very similar to my 1st post fixes (tested and working). It seems to be correct (difference only in some const decls). With simple workspace I cannot seen this bug. This bug appears when we are running a squirrel script from script console. Script is generating and building lot of projects automatically for testing purpose.