Problems creating a new Class Based on tsStatic
by Jack Stone · in Torque 3D Professional · 09/28/2014 (10:39 am) · 7 replies
Hello,
I am trying to create a new class based on tsStatic. I have copied tsStatic.cpp and .h, and changed all of the classnames. Everything compiles and links fine, I can drop instances of my new classes objects into the game, and the art shows up.
However, when I try to stand on the shape with the player, I get an instant crash in line 379 of sceneObject.h, here:
/// Return the type mask that indicates to which broad object categories
/// this object belongs.
U32 getTypeMask() const { return mTypeMask; }
Looking at it with the debugger, I see that mTypeMask, as well as most of the other fields, have not been set. I see that tsStatic is derived from sceneobject, so it seems that changing the classnames to create a new class has broken some kind of initialisation routine of the sceneobject base class.
My art works fine when using a TSStatic.
Can anyone shed any light on this?
Thanks!
I am trying to create a new class based on tsStatic. I have copied tsStatic.cpp and .h, and changed all of the classnames. Everything compiles and links fine, I can drop instances of my new classes objects into the game, and the art shows up.
However, when I try to stand on the shape with the player, I get an instant crash in line 379 of sceneObject.h, here:
/// Return the type mask that indicates to which broad object categories
/// this object belongs.
U32 getTypeMask() const { return mTypeMask; }
Looking at it with the debugger, I see that mTypeMask, as well as most of the other fields, have not been set. I see that tsStatic is derived from sceneobject, so it seems that changing the classnames to create a new class has broken some kind of initialisation routine of the sceneobject base class.
My art works fine when using a TSStatic.
Can anyone shed any light on this?
Thanks!
#2
Add a new entry for your custom object here: objectTypes.h - around Ln. 148
Add a new entry for your custom object here as well: gameFunctions.cpp - around Ln. 463
Finally, be sure to add the new Typemask in your custom object's .cpp file: customObject.cpp
In my case, I just added it to the list of already available TypeMasks. Unfortunately, I haven't been able to test this new TypeMask yet since we have a problem with the castRay function for the object currently. Let me know how it turns out for you. Good luck!
Also I see Danny just posted. He's very knowledgeable and it's likely he's got it right. In the event you did want to try to add a TypeMask, there you go, but first I'd try Danny's suggestions :)
09/28/2014 (3:17 pm)
Hi Jack. I'm relatively new with perusing the source code myself, but recently I had a similar issue. In my case we just wanted to add a new TypeMask altogether, and in your case it just might work. AndrewMac helped me learn how to do this by following these steps:CustomObjectType = BIT(23),
Con::setIntVariable("$TypeMasks::CustomObjectType", CustomObjectType);mTypeMask |= StaticObjectType | StaticShapeObjectType | CustomObjectType;
In my case, I just added it to the list of already available TypeMasks. Unfortunately, I haven't been able to test this new TypeMask yet since we have a problem with the castRay function for the object currently. Let me know how it turns out for you. Good luck!
Also I see Danny just posted. He's very knowledgeable and it's likely he's got it right. In the event you did want to try to add a TypeMask, there you go, but first I'd try Danny's suggestions :)
#3
Yes, I have only done a find/replace for the name, and I have checked with WinMerge that I have not changed anything else.
My typemask is exactly as it should be:
" mTypeMask |= StaticObjectType | StaticShapeObjectType;"
and my constructor is being called.
I think the reason why it's crashing it because the member variable (as well as the other member variables) are not set or invalid.
There doesn't seem to be anything too noteworthy in my callstack:
@Jesse:
I will certainly try your suggestion, it sounds like it could work. I have added custom type masks before, but I didn't think to try one here.
09/28/2014 (3:35 pm)
Hello,Yes, I have only done a find/replace for the name, and I have checked with WinMerge that I have not changed anything else.
My typemask is exactly as it should be:
" mTypeMask |= StaticObjectType | StaticShapeObjectType;"
and my constructor is being called.
I think the reason why it's crashing it because the member variable (as well as the other member variables) are not set or invalid.
There doesn't seem to be anything too noteworthy in my callstack:
> P152_DEBUG.dll!SceneObject::getTypeMask() Line 379 + 0xf bytes C++ P152_DEBUG.dll!Player::_findContact(SceneObject * * contactObject, Point3F * contactNormal, Vector<SceneObject *> * outOverlapObjects) Line 5122 + 0xf bytes C++ P152_DEBUG.dll!Player::findContact(bool * run, bool * jump, Point3F * contactNormal) Line 5167 C++ P152_DEBUG.dll!Player::updateMove(const Move * move) Line 2749 C++ P152_DEBUG.dll!Player::processTick(const Move * move) Line 2128 C++ P152_DEBUG.dll!StdClientProcessList::onTickObject(ProcessObject * obj) Line 214 C++ P152_DEBUG.dll!ProcessList::advanceObjects() Line 269 C++ P152_DEBUG.dll!StdClientProcessList::advanceObjects() Line 246 C++ P152_DEBUG.dll!StdClientProcessList::onAdvanceObjects() Line 183 C++ P152_DEBUG.dll!ProcessList::advanceTime(unsigned int timeDelta) Line 237 + 0xd bytes C++ P152_DEBUG.dll!StdClientProcessList::advanceTime(unsigned int timeDelta) Line 121 + 0xc bytes C++ P152_DEBUG.dll!clientProcess(unsigned int timeDelta) Line 219 + 0x19 bytes C++ P152_DEBUG.dll!processTimeEvent(int elapsedTime) Line 183 + 0x9 bytes C++ P152_DEBUG.dll!fastdelegate::FastDelegate1<int,void>::InvokeStaticFunction(int p1) Line 1018 + 0xe bytes C++ P152_DEBUG.dll!fastdelegate::FastDelegate1<int,void>::operator()(int p1) Line 990 + 0x1a bytes C++ P152_DEBUG.dll!Signal<void __cdecl(int)>::trigger(int a) Line 567 C++ P152_DEBUG.dll!Journal::Call<Signal<void __cdecl(int)>,int>(Signal<void __cdecl(int)> * obj, void (int)* method, int a) Line 634 + 0xa8 bytes C++ P152_DEBUG.dll!JournaledSignal<void __cdecl(int)>::trigger(int a) Line 81 + 0x12 bytes C++ P152_DEBUG.dll!TimeManager::_updateTime() Line 47 C++ P152_DEBUG.dll!fastdelegate::FastDelegate0<void>::operator()() Line 905 + 0x16 bytes C++ P152_DEBUG.dll!Signal<void __cdecl(void)>::trigger() Line 549 C++ P152_DEBUG.dll!Process::processEvents() Line 95 C++ P152_DEBUG.dll!StandardMainLoop::doMainLoop() Line 610 + 0x5 bytes C++ P152_DEBUG.dll!torque_enginetick() Line 120 + 0x5 bytes C++ P152_DEBUG.dll!TorqueMain(int argc, const char * * argv) Line 386 + 0x5 bytes C++ P152_DEBUG.dll!torque_winmain(HINSTANCE__ * hInstance, HINSTANCE__ * __formal, char * lpszCmdLine, HINSTANCE__ * __formal) Line 461 + 0x17 bytes C++ P152_DEBUG.exe!WinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, char * lpszCmdLine, int nCommandShow) Line 64 + 0x16 bytes C++ P152_DEBUG.exe!__tmainCRTStartup() Line 275 + 0x2c bytes C P152_DEBUG.exe!WinMainCRTStartup() Line 189 C kernel32.dll!75c133aa() [Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll] ntdll.dll!77d29ef2() ntdll.dll!77d29ec5()
@Jesse:
I will certainly try your suggestion, it sounds like it could work. I have added custom type masks before, but I didn't think to try one here.
#4
09/28/2014 (3:47 pm)
If you step up into _findContact(), can you verify that the pointer the code is trying to call getTypeMask on is a valid pointer? There's no way a U32 can be 'invalid' in a way that causes a crash - it's not like you're dereferencing a null pointer or something. But the 'this' pointer may be invalid, which means something's going wrong in _findContact.
#5
findContact seems fine, it looks like that object is valid? I'm not seeing anything obviously wrong there at least, whereas there are a bunch of these in getTypeMask:
"CXX0017: Error: symbol "" not found"
I'm not seeing any of those in findContact at all.
09/28/2014 (7:08 pm)
@Daniel:findContact seems fine, it looks like that object is valid? I'm not seeing anything obviously wrong there at least, whereas there are a bunch of these in getTypeMask:
"CXX0017: Error: symbol "" not found"
I'm not seeing any of those in findContact at all.
#6
09/29/2014 (7:21 pm)
Weird. Do you want to throw your code up somewhere to see if someone can reproduce the issue?
#7
https://github.com/PhoenixGameDevelopment/DynamicObjects
It's basically tsStatic with the class names changed, and this:
[code]
ImplementEnumType( DOMeshType,
"Type of mesh data available in a shape.\n"
"@ingroup gameObjects" )
{ DynamicObject::None, "None", "No mesh data." },
{ DynamicObject::Bounds, "Bounds", "Bounding box of the shape." },
{ DynamicObject::CollisionMesh, "Collision Mesh", "Specifically desingated \"collision\" meshes." },
{ DynamicObject::VisibleMesh, "Visible Mesh", "Rendered mesh polygons." },
EndImplementEnumType;
{/code]
Changed to "DOMeshType" from "TSMeshtType".
09/30/2014 (10:02 am)
Sure. I uploaded it here:https://github.com/PhoenixGameDevelopment/DynamicObjects
It's basically tsStatic with the class names changed, and this:
[code]
ImplementEnumType( DOMeshType,
"Type of mesh data available in a shape.\n"
"@ingroup gameObjects" )
{ DynamicObject::None, "None", "No mesh data." },
{ DynamicObject::Bounds, "Bounds", "Bounding box of the shape." },
{ DynamicObject::CollisionMesh, "Collision Mesh", "Specifically desingated \"collision\" meshes." },
{ DynamicObject::VisibleMesh, "Visible Mesh", "Rendered mesh polygons." },
EndImplementEnumType;
{/code]
Changed to "DOMeshType" from "TSMeshtType".
Torque Owner Daniel Buckmaster
T3D Steering Committee
Is your class's constructor being called? Also, having a crash on that method doesn't seem to make sense. All it does is access a member variable - there's really any way that can crash. What does the call stack look like?