Comments (5)
Yea, I've seen that issue before and you're right, BlueprintGeneratedClasses need some fixes for StaticClass
.
I don't think finding the class every time without any caching is feasible, as most people use StaticClass
per-tick to check object-types.
A solutions I am considering is to store the index rather than the pointer and verify the validity of the index of the class every time StaticClass is called.
Pseudo-cpp:
class UClass* ABP_CharacterLightController_C::StaticClass()
{
static int32 ClassIdx = 0x0;
/* Could be external function, not really unique to this StaticClass functon */
static auto SetClassIndex = [](UClass* Object, int32& Index) -> UClass*
{
if (Object)
Index = Object->Index;
return Object;
};
if (ClassIdx == 0x0)
return SetClassIndex(UObject::FindClassFast("BP_CharacterLightController_C"), ClassIdx);
UClass* ClassObj = static_cast<UClass*>(UObject::GObjects->GetByIndex(ClassIdx));
/* Could use cast flags too to save some string comparisons */
if (!ClassObj || ClassObj->GetName() != "BP_CharacterLightController_C")
return SetClassIndex(UObject::FindClassFast("BP_CharacterLightController_C"), ClassIdx);
return ClassObj;
}
from dumper-7.
A solutions I am considering is to store the index rather than the pointer and verify the validity of the index of the class every time StaticClass is called.
class UClass* ABP_CharacterLightController_C::StaticClass() { static int32 ClassIdx = 0x0; /* Could be external function, not really unique to this StaticClass functon */ static auto SetClassIndex = [](UClass* Object, int32& Index) -> UClass* { if (Object) Index = Object->Index; return Object; };
The problem with this is the class object can get destroyed at any point in time, and then once you try to access it, you might be accessing not accessible memory or just garbage memory.
When I was trying to figure out the bugs in the code, once the blueprint class actually gets loaded, the old class object would point to a different object, it wasn't even a class object. And I was just lucky that another object was put at the same memory location as the old class object, so I could get its' name without crashing.
Other times might not be that lucky and once you try to access Object->Index, you might be accessing either inaccessible memory or just garbage reallocated memory, so you can't just check if memory is accessible with IsBadReadPtr(Object): it will be accessible but something else is there now.
I don't think finding the class every time without any caching is feasible, as most people use
StaticClass
per-tick to check object-types.
Well, that will be on programmers to cache and reset the pointers. I get the class only once at match start and then invalidate on match end, because that's when levels get loaded and unloaded, so it's always correct.
To actually be able to cache these class pointers, you'd need to hook into the object destruction function, and then have like a vector of UClass**(to the fields in each class, so you'd make a field static UClass* StaticClass
in each class), and then invalidate those pointers once UClass object gets destroyed ABP_CharacterLightController_C::StaticClass = nullptr
, but using the vector of those pointers to the UClass pointers, because you'd be doing it from inside of the object destruction hook. That would fix it, there would be no way to get invalid UClass pointer this way at any point in time, as I understand it.
from dumper-7.
The problem with this is the class object can get destroyed at any point in time,
I am aware of this. In the proposed code above I'm explicitly not storing a UClass*
, but rather the index of the class from the previous (re-)initialization. Re-fetching the Class from the index will return nullptr if the index was invalidated. If the index is still valid, but the object at said index was changed the check ClassObj->GetName() != "BP_CharacterLightController_C")
fails and the object will be re-initialized.
from dumper-7.
A fix for the issue has been implemented, but it is mostly untested. It would be nice if you could test the latest commit on main and tell me if StaticClass is still crashing with BP geneated classes.
I'll leave this issue ope until you can confirm it's been fixed.
from dumper-7.
As you seemingly don't care about this issues anymore and it has been fixed, I'm going to close this.
from dumper-7.
Related Issues (20)
- Cyclic dependencies on duckside.
- Functions of reloaded blueprint classes can't be called after reload.
- abstütz bei ark survival evolved
- static_assert Errors HOT 3
- Feature request: exchange Pad_Address for Pad_Position HOT 3
- Error in UnrealContainers! TArray end. It will make the game crash. HOT 5
- This source has alot of weird characters for some reason and duplicated struct names.. HOT 2
- Sea of thieves Crash HOT 1
- Doesnt work for Calabiyau
- Doesnt work for Calabiyau HOT 1
- Static Assertion failed with ********* has a wrong offset HOT 1
- Doesnt work for Calabiyau HOT 1
- Using The SDK HOT 1
- Error Static_assert HOT 3
- Suggestion: Have an option to alphabetically sort the header includes in SDK.h (makes it easier to manually include) HOT 3
- Access Violation, UE 4.27.2 Hogwarts Legacy, GNames Not Found HOT 1
- static_assert Static assertion failed HOT 4
- Access Violation in ObjectArray with Soulmask game HOT 8
- Member redefinition in classes generated by dumper (Deceit2 UE 5.4.1) HOT 11
- Back 4 Blood Decrypt Key HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dumper-7.