Ticket #1522: CrashApp.2.cpp

File CrashApp.2.cpp, 1.7 KB (added by julun, 17 years ago)
Line 
1#include <View.h>
2#include <Debug.h>
3#include <Bitmap.h>
4#include <Window.h>
5#include <Application.h>
6
7#define CRASH
8
9class OffscreenView : public BView {
10 public:
11 OffscreenView(BRect frame, char *name)
12 : BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW) { }
13
14 void DrawX()
15 {
16 ASSERT(Window());
17 if (Window()->Lock()) {
18 FillRect(Bounds());
19 Sync();
20 Window()->Unlock();
21 }
22 }
23};
24
25
26class View : public BView {
27 public:
28 View(BRect rect, char *title)
29 : BView(rect, title, B_FOLLOW_NONE, B_WILL_DRAW)
30 {
31 fOffscreen = new BBitmap(rect, B_CMAP8, true);
32 fOffscreenView = new OffscreenView(rect, "offscreen");
33
34 if (fOffscreen != NULL && fOffscreen->Lock()) {
35 fOffscreen->AddChild(fOffscreenView);
36 fOffscreen->Unlock();
37
38 fOffscreenView->DrawX();
39 }
40 }
41
42 ~View()
43 {
44 delete fOffscreen;
45 }
46
47 private:
48 BBitmap *fOffscreen;
49 OffscreenView *fOffscreenView;
50};
51
52
53class Window : public BWindow {
54 public:
55 Window(BRect rect, const char* name)
56 : BWindow(rect, name, B_TITLED_WINDOW, B_NOT_RESIZABLE)
57 {
58#ifndef CRASH
59 view = new View(BRect(0, 0, 82, 82), "view");
60 AddChild(view);
61#endif
62 }
63
64 bool QuitRequested()
65 {
66 be_app->PostMessage(B_QUIT_REQUESTED);
67 return true;
68 }
69
70 View *view;
71};
72
73
74class CrashApp : public BApplication {
75 public:
76 CrashApp()
77 : BApplication("application/x-vnd.CrashApp")
78 {
79#ifdef CRASH
80 view = new View(BRect(0, 0, 82, 82), "view");
81#endif
82
83 window = new Window(BRect(100, 100, 182, 182), "window");
84
85#ifdef CRASH
86 window->Lock();
87 window->AddChild(view);
88 window->view = view;
89#endif
90
91 window->Show();
92
93#ifdef CRASH
94 window->Unlock();
95#endif
96 }
97
98 private:
99 View *view;
100 Window *window;
101};
102
103
104int
105main(int argc, char** argv)
106{
107 CrashApp app;
108 app.Run();
109
110 return 0;
111}