I have again tried to find out the reason of this crash, to no avail so far. Interestingly, the problem only occurs when Thor/SFML are linked dynamically (in either debug or release mode). The application also crashes without the
m_callbackSystem.connect() call (I also omitted
operator|| and replaced
sf::RenderWindow with
sf::Window). I haven't been able to further reduce the code:
#include <SFML/Window.hpp>
#include <Thor/Events.hpp>
int main()
{
sf::Window window(sf::VideoMode(640, 480), "window");
thor::ActionMap<std::string>::CallbackSystem m_callbackSystem;
thor::ActionMap<std::string> m_actionsTable(window);
m_actionsTable["exit"] = thor::Action(sf::Keyboard::Escape, thor::Action::PressOnce);
while (window.isOpen())
{
m_actionsTable.update();
m_actionsTable.invokeCallbacks(m_callbackSystem);
window.display();
}
}
There occurs a heap corruption at the destruction of the
result variable in
thor::ActionMap::invokeCallbacks(). To be more precise, the
operator delete deallocation in
std::vector fails.
From my experience, heap corruptions most often occur when something is deleted twice or incorrectly. Since Thor uses zero direct
delete operations in its code (everything is encapsulated), this is very improbable. I even changed the
thor::Action implementation to use
std::unique_ptr instead of
aurora::CopiedPtr, just to exclude bugs in my smart pointers. The result remained the same.
As mentioned earlier, I still guess it is a configuration/library issue, furthermore this is enforced by the fact that Thor with dynamically linked runtime runs well. I have checked the verbose linker output and apparently, SFML, Thor and the project use the same runtime DLLs (libcmt.dll and libcmtd.dll, respectively).
So the only thing I could imagine is that there are specific compiler flags that are incompatible to each other. Does SFML change specific VS project properties, except for /MT or /MTd flags? Or maybe CMake? I will also try with a CMake-generated application.