I make a callback to resize the window, and respond to resizing the renderer. Well, declared typedef , window class and renderer class are in different libraries. Made an announcement:

 class renderer; typedef bool(__thiscall renderer::*renderer_resize_callback_t)(unsigned, unsigned) const; 

Next, after the renderer was created, I write a pointer to the resize method in the window class:

 class API_WINDOWS window { ... renderer *p_renderer_; renderer_resize_callback_t m_resize_callback_t_; public: ... void set_resize_callback(direct2d::renderer_resize_callback_t resize_callback_t); }; 
 void window::set_resize_callback(const renderer_resize_callback_t resize_callback_t) { m_resize_callback_t_ = resize_callback_t; } 
 class API_RENDERER renderer { protected: ID2D1Factory* p_factory_; ID2D1HwndRenderTarget* p_render_target_; public: renderer(const void* window_handle, int w, int h); ~renderer(); void draw() const; bool __thiscall resize_target(unsigned width, unsigned height) const; renderer() = delete; renderer(const renderer&) = delete; renderer(const renderer&&) = delete; renderer& operator=(const renderer&) = delete; renderer& operator=(const renderer&&) = delete; }; 
 bool __thiscall renderer::resize_target(const unsigned width, const unsigned height) const { const HRESULT result = p_render_target_->Resize(D2D1::SizeU(width, height)); return !(FAILED(result)); } 

Next, I try to write a pointer to the renderer class and to the resize method in the class by calling the set_resize_callback method:

 window wnd(1024, 768); renderer renderer(wnd.get_window_handle(), 1024, 768); wnd.set_renderer(&renderer); wnd.set_resize_callback(&renderer::resize_target); 

But after the method is called, an exception will occur:

Run-Time Check Failure # 0 - The value of the ESP has not been properly saved across a function call. It is usually a convention.

As I understand it, it says that the calling agreement does not match, and it damaged the stack. But how? The definition of the prototype explicitly states the agreement, as well as the method.

Can this be fixed?

  • And where is the set_resize_callback and resize_target and renderer code? Why is there __thiscall ? - VTT
  • __thiscall was added after I received this exception without explicitly specifying calling conventions, thinking that this would fix the problem, but it had absolutely no effect. - LLENN
  • "the window class and renderer class are in different libraries" - and these libraries are assembled with the same settings? - VTT
  • They are collected identically to each other. - LLENN
  • And if you just call renderer.resize_target then there will be no problem? You should also check that the pointer values ​​in the window object are correct and correspond to those that can be obtained inside the renderer library. - VTT

0