Game Development Community

crtdbg.h error when compiling (building) my project (Box2D-TGB integration)

by Holmida · in Torque Game Builder · 08/17/2011 (4:45 pm) · 2 replies

Ok now, this is my situation. I'm integrating Box2D v2.0.1 into TGB v1.7.5 Pro, as from Michael Wroeister's thesis in tgb-box2d-integration.googlecode.com/files/Integrating%20Box2D%20into%20TGB%201..... I'll describe the process step by step, just in case someone can see what I'm doing wrong.

First of all, I add the TORQUE_DISABLE_MEMORY_MANAGER code to winMemory.cc in the platformWin32 folder. I build the visual studio solution and it does it correctly, no errors. Then, I build the Box2D solution (so it creates box2d.lib) in Release Mode, everything is OK. After that, I add box2d.vcproj to my TGBGame visual studio project, and add the directories and libraries I need to TGBGame's Configuration options (C++-General, Linker-General and Linker-Input), and in its project dependencies I check Box2D. Then I change the parts of the code within iTickable.cc, td2Physics.h, etc, again compile to build the solution in Release Mode, and everything is OK: no errors, 1 correct and some updates.

Then, in TGBGame, Source, I create a sub-folder called Box2D and add the files from the wrapper (Box2dWorldRef.cc, Box2dWorldRef.h, Box2dBodyRef.cc...), and THEN, when building the solution, it gives me 1 incorrect message and this alert text:

TGBGame - 54 errors, 9 warnings

Also, it displays tons of lines about errors from some file called "crtdbg.h"

c:Program Files (x86)Microsoft Visual Studio 9.0VCincludecrtdbg.h(1135) : error C2226: syntax error: unexpected type 'size_t'

Previously, the compiler didn't say anything. Maybe it's related to all the wrapper files? I think I've added them correctly to the T2D TGBGame folder in the visual studio project.

Then, I did something I hadn't done initially, adding TORQUE_DISABLE_MEMORY_MANAGER to the TGBGame's Properties in C/C++ -> Preprocessor -> definitions. After that, the compiler (Release) gives me only one line of error:

1>c:program files (x86)torquetorque game builder 1.7.5 proenginesourceplatformwin32winmemory.cc(50): error C2084: function 'void operator delete(void *,void *) throw()' already has a body

Which aims to this 'winMemory.cc' command line:

void FN_CDECL operator delete(void *, void *) {}

If I run the 'Generate Solution' option, now in Debug, it gives me this lines:

1>C:Program Files (x86)MSBuildMicrosoft.Cppv4.0Microsoft.CppBuild.targets(990,5): warning MSB8012: TargetPath(C:Program Files (x86)TorqueTorque Game Builder 1.7.5 ProenginecompilersVisualStudio 2008../../Link/Debug.Win32TGBGame.exe) doesn't match with the propertie's value OutputFile of Linker (C:Program Files (x86)TorqueTorque Game Builder 1.7.5 ProtgbgameDataT2DProjectTGBGame_DEBUG.exe). This may cause the project to not compile correctly. To solve this problem, make sure that the property's values $(OutDir), $(TargetName) y $(TargetExt) match with the specified value in %(Link.OutputFile).

1>C:Program Files (x86)MSBuildMicrosoft.Cppv4.0Microsoft.CppBuild.targets(992,5): warning MSB8012: TargetName(TGBGame) doesn't match with the propertie's value OutputFile of Linker (TGBGame_DEBUG).This may cause the project to not compile correctly. To solve this problem, make sure that the property's values $(OutDir), $(TargetName) y $(TargetExt) match with the specified value in %(Link.OutputFile).

1>winMemory.obj : error LNK2005: already defined "void * __cdecl operator new(unsigned int,void *)" (??2@YAPAXIPAX@Z) in Box2dWorldRef.obj

1>winMemory.obj : error LNK2005: already defined "void __cdecl operator delete(void *,void *)" (??3@YAXPAX0@Z) in t2dPhysics.obj

1>../../../tgb/gameData/T2DProject/TGBGame_DEBUG.exe : fatal error LNK1169: one or more symbols simultaneously defined were found.

But I haven't change anything aside from the TORQUE_DISABLE_MEMORY_MANAGER thing. Does anyone know something about ALL this mess? I'm starting this new thread because I'm abusing a lot from Michael Wroeister in the 'Box2D Integration on Google Code' thread, and maybe some other user knows about this issue. Thank you in advantage.

#1
08/18/2011 (12:49 am)
I think I can see a solution at page 12 of the paper you are posted a link to. Michael must have forgot to mention that you need TGB's 'operator delete' undefined too, or maybe it just wasn't there for version 1.7.4 (really?). Either way, he explains there what he does and why, so you should be able to adjust his instructions for your case, if you read carefully.
#2
08/18/2011 (8:32 am)
Ok, now it works!! You are right, here's the solution, just in case someone experiences this issue in the future (all credits to Michael Wroeister):

The definition of "operator delete" is new in TGB 1.7.5, so it is not mentioned in the thesis. Coding 'winMemory.cc' as written in the pdf generates many errors. The code should look like this:

#ifndef TORQUE_DISABLE_MEMORY_MANAGER
#ifndef _WINDOWS
void* FN_CDECL operator new(dsize_t, void* ptr)
{
   return (ptr);
}

// delete if placement new fails

void FN_CDECL operator delete(void *, void *) {}
#endif
#endif