Ticket #16636: clipboard-show.cxx

File clipboard-show.cxx, 2.1 KB (added by martin.steghoefer, 6 years ago)

First example; can reproduce both holes (by activating/deactivating the "wxSleep")

Line 
1#include <wx/wxprec.h>
2#ifndef WX_PRECOMP
3#include <wx/wx.h>
4#endif
5
6
7#include <wx/app.h>
8#include <wx/clipbrd.h>
9#include <wx/defs.h>
10
11
12// AssertHandler --------------------------------------------
13
14
15void assertHandler(
16    const wxString &file, int line, const wxString &func,
17    const wxString &cond, const wxString &msg)
18{
19    std::cout << "assertion failed: "
20        << file << " / "
21        << line << " / "
22        << func << " / "
23        << cond << " / "
24        << msg << std::endl;
25}
26
27
28// Frame ----------------------------------------------------
29
30
31class CustomFrame : public wxFrame
32{
33public:
34    CustomFrame()
35    : wxFrame(NULL, 1, wxT("CustomFrame"))
36    {}
37   
38    void OnShow(wxShowEvent& event)
39    {
40        // simple clipboard operation with reentry
41        wxTheClipboard->IsSupported(wxDF_TEXT);
42    }
43   
44    DECLARE_EVENT_TABLE()
45};
46
47
48BEGIN_EVENT_TABLE(CustomFrame, wxFrame)
49  EVT_SHOW(CustomFrame::OnShow)
50END_EVENT_TABLE()
51
52
53// App ------------------------------------------------------
54
55
56class MyApp : public wxApp
57{
58public:
59    virtual bool OnInit()
60    {
61        wxSetAssertHandler(assertHandler);
62        CustomFrame *frame = new CustomFrame();
63        frame->Show();
64       
65        // Activate or deactivate the following line to switch
66        // between the 2 stacktraces:
67        // With sleep:    Stacktrace through g_timeout_dispatch
68        //                and request_frame_extents_timeout
69        // Without sleep: Stacktrace through wxgtk_main_do_event
70        wxSleep(3);
71
72        return true;
73    }
74   
75    virtual void OnEventLoopEnter(wxEventLoopBase *loop)
76    {
77        // simple clipboard operation (calls wxGUIEventLoop::YieldFor)
78        wxTheClipboard->IsSupported(wxDF_TEXT);
79       
80        // Note: It may be unorthodox to do clipboard operations
81        // in OnEventLoopEnter, but this is not the root of the
82        // problem. There are a thousand other ways to reproduce the
83        // problem, but they all depend heavily on the timing and are
84        // therefore not suitable for this bug report (unreliable).
85    }
86};
87
88
89IMPLEMENT_APP(MyApp);
90
91