MC2 Editor

I can not see the MC2 Editor being part of the XNA project.

When I build/rebuild MC2 the editor files are not updated.

What do I do wrong ?

or

How can I make changes and updates to the MC2 editor?

[233 byte] By [wolfman-x] at [2008-2-12]
# 1

Correct, the editor project is not part of the XNA build projects because Visual C++ Express cannot build them as they require MFC. If you have Visual Studio Standard or Professional you can build the project with no problems. In the Source\Editor folder you will find the projects for building the editor code. Compile both of these: EditorMFC.vcproj and Editores.vcproj and you should be set.

Thanks!

MichaelKlucher-MSFT at 2007-9-10 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technolgies: XNA Build...
# 2

OK;great got it. I made some minor changes consistant in all relevant files in the editor folder and compiled it and it works as long as I stay inside the editor and don't save anything (just to give you one example of what I did: I added 10 more different skys for selection and I can select and view them in the editor).

At the point I try to save the file the editor crashes with an error message stating an unidentified rootcause. This is all very usuall for the first experiment and I can figure it out; the real questions out of this experiment are:

Do I need to change both, the editor project and the game project, before it will work?

Are there files like mc2res.dll or any others that are changed by the editor and the game project?

Which area (editor or game) has to be changed first?

wolfman-x at 2007-9-10 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technolgies: XNA Build...
# 3

I tried the editor version that comes with the source code release without any modifications and this one crashes with the same error message; might well be not my changes that create the issue; here are two re-occuring error messages:

EXCEPTION : Unknown exception code 0xC0150010 in NTDLL! (+0x42345)
Address : 0x7C943345
Location : NTDLL! (+0x42345)

EXCEPTION : Attempt to write to address 0x06150038 in EDITREL! (+0xBF1ED)
Address : 0x004C01ED
Location : EDITREL! (+0xBF1ED)

Any idea what is going wrong?

wolfman-x at 2007-9-10 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technolgies: XNA Build...
# 4

When are you getting the error and/or what steps do you take to make this happen? Is it just when you run the program? I'm not seeing that here, but let me know. Are you running the editor from the FinalBuild directory?

Thanks!

MichaelKlucher-MSFT at 2007-9-10 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technolgies: XNA Build...
# 5

I can statrt the editor from the final built folder or copy it into a standard installation of MC2.

I open it ,create new mission (whatever size or base texture: same effect) and give it a name or not, change some parameters or not (no impact at all) and save or save as...==> error message

wolfman-x at 2007-9-10 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technolgies: XNA Build...
# 6

Cool thanks. I get the same thing here and am looking into it. I'll let ya know once I find the problem. (Has something to do with deleting a pointer)

MichaelKlucher-MSFT at 2007-9-10 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technolgies: XNA Build...
# 7
Any findings? I am stuck with the problem
wolfman-x at 2007-9-10 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technolgies: XNA Build...
# 8

I haven't found the root of the problem but you can "work around" it by commenting the first half of line 1738 in EditorInterface.cpp which is the "delete curDirStr;"

I haven't tested if this causes any other problems so use this at your own risk. I'll try to have a real solution within the week.

Thanks
Michael

MichaelKlucher-MSFT at 2007-9-10 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technolgies: XNA Build...
# 9

Sorry for the really long delay with this but I have the proper solution now.

In EditorInterface.cpp go to line 1734 you should see this line of code:

TCHAR *curDirStr = new TCHAR[curDirStrSize];

Change the line to this:

TCHAR *curDirStr = (TCHAR *)gos_Malloc(curDirStrSize);

There's also a crash on exit you may want to fix, in EditorData.cpp goto line 953 you should see this line of code:

land->terrainName = new char[strlen(name2)+1];

Change the line to this:

land->terrainName = (char *)gos_Malloc(strlen(name2) + 1);

You should be all set now, let me know if you continue to have problems!

Thanks!

MichaelKlucher-MSFT at 2007-9-10 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technolgies: XNA Build...
# 10

Great; this works. Here is the next problem I am facing.

I can position units on the map and save it.

As soon as I double click on the unit (mech) to change team or skill level or unit color the system crashes with this error message:

EXCEPTION : Unknown exception code 0xC0150010 in NTDLL! (+0x42345)
Address : 0x7C943345
Location : NTDLL! (+0x42345)

It does not matter if I load an existing map or try it with a new map. It works fine for buildings, turrets, prop vehicles... Seems only to occur for mechs and vehicles.

I am stuck with this problem.

wolfman-x at 2007-9-10 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technolgies: XNA Build...
# 11
I just spotted this post.
I hope I misread something, either in your post or in the code itself. If not: are you seriously suggesting to use gos_Malloc to allocate the resource, then pointer (not even array) operator delete function to release it?
There are two valid options for the code here:
1. gos_Malloc / gos_Free.
2. operator new[]() / operator delete[]() (not "operator delete()", "operator delete[]()")..
Using either of "p = new char[ n ]" or "p = gos_Malloc(n)" and later releasing that memory with "delete p;" is obviously an error.
To spell it out:
Never use mismatched resource allocation/release functions.
This also illuminate what I believe to be an oversight in MFCPlatform.cpp. It doesn't implement "operator delete[]()" while GamePlatform.cpp does. Not that it would have helped to fix this case, as the code in EditorInterface was already broken and did not use it, but for completeness and consistency perhaps it should be added?

While on the subject of bugs, I think I encountered one in EditorObjectMgr.cpp. In EditorObjectMgr::init() it opens bldgListFileName ("data\arts\buildings.csv"). Please have a quick look at that one in a text editor. The second line starts with "Streetlight3,-1,". Now see what happens in the loop in init(). It extracts the "building" filename. Fine. Next it extracts the group (number)... that is -1. It then tries to cLoadString() id "IDS_GROUPS + group" (into a 64-byte string, make a note of that too), which (obviously or thankfully, depending on view) doesn't exists. That is a bug in itself, trying to access what this code already should know is an invalid resource.
But it gets better. cLoadString() (MCLib\Utilities.h) calls gos_GetResourceString(), which when it notices this resource doesn't exist sets the string it returns to ""%s:%d Not defined"", with the name of the resource dll potentially way to long fro the reciever to handle.
I suspect it worked during development 'cause it wasn't stored in directories with these pathlengths, but in the default installation directory of this release this string when expanded from gos_GetResourceString() ends up as "z:\mechcommander2 source\finalbuild\editores.dll:10099 Not defined", which is 66 characters. I wonder how it comes noone else encountered this. Shorter installation directory path?
Anyway, with a 66-character string returned, cLoadString() throws a fit as this is larger than the 64 bytes of the buffer provided from EditorObjectMgr::init(), resulting in a STOP.
Almost funny to see the result of this tiny little error in EditorObjectMgr::init() :-)
I suggest wrapping "cLoadString( IDS_GROUPS + group, GroupName, 64, gameResourceHandle );" in EditorObjectMgr::init() in "if ( group >= 0) { }".

EDIT: I'm terribly sorry. This is of course not enough, and will always crash in a debug build with /GZ, and only by pure luck in release mode. The correct code must of course be:

if (group >= 0)
{
cLoadString( IDS_GROUPS + group, GroupName, 64, gameResourceHandle );
}
else
{
GroupName[0] = '\0';
}

Sorry for the inconvenience.


It's only hack, and should e.g. strings in editores.dll be edited this will crash anyway, but at least init() wont any more try to access resource ID's it already knows are not for it to probe.

tamlin2 at 2007-9-10 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technolgies: XNA Build...
# 12

There are two more occasions when the same error message shows up (indicating the crash):

1.) you open the objectives setting box and try to select "play wav" as an action

2.) you try to select "make new technology available" as an action

the moment you click on the file you want to select it crashes.

It works fine for "play bik" or "set flag" or the other selections.

wolfman-x at 2007-9-10 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technolgies: XNA Build...
# 13
I'm sorry if it seems like I'm hijacking this thread. I just thought it more appropriate to keep the number of MC2-specific threads as low as possible.
It seems I've stumbled across yet another MC2 Editor bug. When starting the editor and selecting a New Map 60x60, I was more than a bit surprised to see "newmap.tga" ending up at ~9MB while"newmap.burnin.tga" was at the more appropriate size just over 2MB.
Set a breakpoint at CreateScaledColorMap() in EditorData.cpp, and it will all become clear where this bug comes from.
The code unconditionally creates a destination TGA size of the same dimensions as the source JPG, meaning 1536^2. However, even that it does this in error, it only fills the target TGA with 768^2 pixels worth of data (60*12.8 = 768). Then, even that it only used a quarter of the memory allocated, it writes the whole 9MB buffer to disk.
The loop towards the end of the function at first glance doesn't seem to potential memory overrun (like trying to copy 'jpgColorMapWidth * 4' bytes/line into dest), why I currently can't see any other explanation to this than that it's another bug.
Comments?
EDIT: The error is quite simple. It's that it calculates physWidth to be the image width in bytes for a 32-bpp image (4Bpp), but then squares this number too, making it w*h*4*4. The correct fix is to simply replace the two instances of 'physWidth * physWidth' with something more appropriate. 'physWidth * newWidth', or perhaps even 'newWidth * newWidth * 4' to be explicit and help coming generation understand this code quicker.
EDIT2: While at it, perhaps 'image', that becomes allocated from the Heap_TextureOther GOS heap (by the call to DecodeJPG()), also should be released once this function is done with it? Add "void* const pToFree = image;" just after the call to DecodeJPG(), then after "free(tmpImage);", "gos_Free(pToFree);" should be added. While not critical, it's not nice wasting up to ~9MB of the users memory for nothing.
(does it start to seem someone had a somewhat bad day when he wrote that function? :-) )
tamlin2 at 2007-9-10 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technolgies: XNA Build...
# 14
You do hijack my post. I need an answer and not more question that are partially un-related and simply handle file formats or are written such complicated that they do NOT help me at all. Post your own questions independently, please. You might understand software but you do not understand people and what they need.
wolfman-x at 2007-9-10 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technolgies: XNA Build...