Hi,
I found an interesting bug in this amazing project, but since project is frozen, there is no one to fix/do something with it...
So.....how tobex call existing function from bgmain.exe ?
it's almost easy, it declare place(via template<...>) for pointer and put adress to it:
char (EngineClass::*EngineClass_GetSong)(short) = SetFP(static_cast<char (EngineClass::*)(short)> (&EngineClass::GetSong), 0x4D40D6);
To call this complex template tobex uses next line, this is C usual way to call any run-time adress
char EngineClass::GetSong(short id) { (this->*EngineClass_GetSong)(id); }
What's problem ?
Problem is when line {(this->*EngineClass_GetSong)(id);} used for constructors/destructors.
For example class EngineClass may contain embedded variables(fields) with other classes:
class EngineClass { EngineClass::EngineClass() - constructor EngineClass::~EngineClass() - destructor CString MyString; - MyString object embedded to EngineClass }
Ofter tobex also call original EngineClass::EngineClass and EngineClass::~EngineClass as {this->*XXX()} , XXX is original adress inside bgmain.exe and this XXX usually do all work to create/delete EngineClass class.
At this point we must remember what compiler will check all vars inside EngineClass for possible other classes and will add calls to constructors of these classes before execution first programmer's code !
so line {this->*XXX()} will be transformed to:
- for constructor:
1) call CString::CString for MyString
2) call constructorX for variable X
.....
N) this->*XXX()
- for destructor:
1) this->*~XXX()
2) call CString::~CString for MyString
....
N) call destructorX for variable X
XXX and ~XXX written and compiled by BioWare in same MS compiler (VC6 i think), so original code also will call all embedded constructors/destructors. Bug is doubling calls, tobex and game for each class variable can do same job twice !
Probably this is not serious problem, no crashdumps , but in worst case tobex can free again allready free memory because first time memory has been released by game (~XXX), second time in tobex by "hidden" code, generated by compiler.
Edited by Insomniator, 27 October 2020 - 12:32 PM.