So my c++ project is showing some strange behavior.
dyanamic_cast returns null when the type I want it to cast to is definately the right type. I attached a screen shot showing this.
The vtable says RuntimeProperty and that is exactly what I want to cast this to and yet it fails.
I testing dyanmic_cast the line after the object was created and it worked fine but later on it fails.
The problem may be related to the fact that the object is allocated on a custom garbage collected heap.
Does anybody have any insight as to why dyamic_cast would fail even though I can plainly see that the object types match?
dynamic_cast fails
Do you have RTTI properly enabled in the compiler options? Do you invoke undefined behavior such as storing any of your pointers in a void*?
I suspect the object memory is corrupt?
Instead of dynamic cast, can you static cast it for a test and check if the object is still valid?
Instead of dynamic cast, can you static cast it for a test and check if the object is still valid?
dynamic_cast works right after the object is created,
and as a temporary work around I added another virtual method to get the class type as an enumerated type and check the class type using that. Using the enumerated type for type checking joined with a static cast it works fine. It doesn't appear that the block is memory is corrupted. All of the values, including the vtable, are the same as when the object is first initialized.
and as a temporary work around I added another virtual method to get the class type as an enumerated type and check the class type using that. Using the enumerated type for type checking joined with a static cast it works fine. It doesn't appear that the block is memory is corrupted. All of the values, including the vtable, are the same as when the object is first initialized.
The workaround is likely to be hiding the true problem.
Can you simmer it down to a very small test case? As you rip out code, pay close attention to the point where it begins to work and the differences from the previous iteration. If on the other hand it never works, it means you're doing something incorrectly, in which case the sample will highlight to those here what the misunderstanding might be.
Can you simmer it down to a very small test case? As you rip out code, pay close attention to the point where it begins to work and the differences from the previous iteration. If on the other hand it never works, it means you're doing something incorrectly, in which case the sample will highlight to those here what the misunderstanding might be.
What do you see if you expand __vfptr in the debugger?
Also, is any of this crossing module boundaries?
Also, is any of this crossing module boundaries?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement