質問編集履歴
1
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,279 +1,33 @@
|
|
1
|
-
### 問題(Problem)
|
2
|
-
* glfw3を使って、ウィンドウを表示させたいのですが、
|
3
|
-
|
4
|
-
ERROR: Setting <GLFWContentView: 0x1007508a0> as the first responder for window <GLFWWindow: 0x10072f620>, but it is in a different window ((null))! This would eventually crash when the view is freed. The first responder will be set to nil.
|
5
|
-
|
6
|
-
というエラーが出て、表示する途中で落ちてしまいます。
|
7
|
-
どうすれば解決できるでしょうか?
|
8
|
-
|
9
|
-
* My program has a error with glfw3 window. The error is that
|
10
|
-
|
11
|
-
ERROR: Setting <GLFWContentView: 0x1007508a0> as the first responder for window <GLFWWindow: 0x10072f620>, but it is in a different window ((null))! This would eventually crash when the view is freed. The first responder will be set to nil.
|
12
|
-
|
13
|
-
How can I deal with it?
|
14
|
-
|
15
|
-
### 発生している問題・エラーメッセージ(Error)
|
16
|
-
|
17
|
-
```
|
18
|
-
Main[74526:7122089] [General] ERROR: Setting <GLFWContentView: 0x1007508a0> as the first responder for window <GLFWWindow: 0x10072f620>, but it is in a different window ((null))! This would eventually crash when the view is freed. The first responder will be set to nil.
|
19
|
-
(
|
20
|
-
0 AppKit 0x00007fff5520752e -[NSWindow _validateFirstResponder:] + 578
|
21
|
-
1 AppKit 0x00007fff5494ea58 -[NSWindow _setFirstResponder:] + 31
|
22
|
-
2 AppKit 0x00007fff549ed17d -[NSWindow _realMakeFirstResponder:] + 448
|
23
|
-
3 Main 0x0000000100055003 createNativeWindow + 1187
|
24
|
-
4 Main 0x000000010005490f _glfwPlatformCreateWindow + 63
|
25
|
-
5 Main 0x000000010004d167 glfwCreateWindow + 887
|
26
|
-
6 Main 0x000000010000caa1 _ZN6WindowC2EiiPKc + 97
|
27
|
-
7 Main 0x0000000100008e59 _ZN6WindowC1EiiPKc + 41
|
28
|
-
8 Main 0x000000010000855c main + 156
|
29
|
-
9 libdyld.dylib 0x00007fff7ebc4115 start + 1
|
30
|
-
)
|
31
|
-
|
32
|
-
```
|
33
|
-
|
34
|
-
### 該当のソースコード
|
35
|
-
|
36
|
-
```c++
|
37
|
-
#include <GL/glew.h>
|
38
|
-
#include <GLFW/glfw3.h>
|
39
|
-
#include <chrono>
|
40
|
-
#include <iostream>
|
41
|
-
#include <thread>
|
42
|
-
#include "./MendelsEngine/Model/UI/Window.h"
|
43
|
-
#include "./MendelsEngine/State/Scene/Scene.h"
|
44
|
-
|
45
|
-
/* 変数名の省略の対応表
|
46
|
-
global: g
|
47
|
-
pointer: p
|
48
|
-
member: m
|
49
|
-
array: a
|
50
|
-
vector: vec
|
51
|
-
matrix: mat
|
52
|
-
index: id
|
53
|
-
count: cou
|
54
|
-
number: num
|
55
|
-
value: val
|
56
|
-
|
57
|
-
allocate: alloc,
|
58
|
-
buffer: buf,
|
59
|
-
current: cur,
|
60
|
-
dimension: dim,
|
61
|
-
direction: dire,
|
62
|
-
event: ev,
|
63
|
-
fragment: frag
|
64
|
-
height: hei,
|
65
|
-
inverse: inv,
|
66
|
-
location: loc,
|
67
|
-
medium: med,
|
68
|
-
multiply: mult,
|
69
|
-
normal : norm,
|
70
|
-
perspective: persp,
|
71
|
-
position: pos,
|
72
|
-
previous: pre,
|
73
|
-
projection: proj,
|
74
|
-
random: rand,
|
75
|
-
string: str,
|
76
|
-
target: tar,
|
77
|
-
texture: tex,
|
78
|
-
vertex: vert,
|
79
|
-
volume: vol,
|
80
|
-
width: wid,
|
81
|
-
win: win
|
82
|
-
*/
|
83
|
-
|
84
|
-
int main() {
|
85
|
-
|
86
|
-
/* 初期化 */
|
87
|
-
|
88
|
-
/// GLFW を初期化する。
|
89
|
-
if (glfwInit() == GL_FALSE) {
|
90
|
-
// 初期化に失敗した。
|
91
|
-
std::cerr << "Can't Initialize GLFW" << std::endl;
|
92
|
-
};
|
93
|
-
|
94
|
-
// プログラム終了時の処理を登録する。
|
95
|
-
atexit(glfwTerminate);
|
96
|
-
|
97
|
-
//// OpenGL Version 3.2 Core Profile を選択する。
|
98
|
-
//glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
99
|
-
//glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
|
100
|
-
//glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
101
|
-
//glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
102
|
-
|
103
|
-
// ゲーム画面を構築するインスタンス生成。
|
104
|
-
// インスタンスへの参照を他クラスへ渡し、他クラスでもその処理を行えるようにする。
|
105
|
-
Window win;
|
106
|
-
Scene scene;
|
107
|
-
|
108
|
-
// 背景色を指定する。
|
109
|
-
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
|
110
|
-
|
111
|
-
// 背面カリングを有効にする。
|
112
|
-
glFrontFace(GL_CCW);
|
113
|
-
glCullFace(GL_BACK);
|
114
|
-
glEnable(GL_CULL_FACE);
|
115
|
-
|
116
|
-
// デプスバッファを有効にする。
|
117
|
-
glClearDepth(1.0);
|
118
|
-
glDepthFunc(GL_LESS);
|
119
|
-
glEnable(GL_DEPTH_TEST);
|
120
|
-
|
121
|
-
// ゲームループの変数初期化。
|
122
|
-
const std::chrono::milliseconds MS_PER_UPDATE(10);
|
123
|
-
std::chrono::milliseconds lag;
|
124
|
-
auto pre = std::chrono::system_clock::now();
|
125
|
-
|
126
|
-
// メインゲームループ。ゲームループでゲームを更新し、描画し続ける。
|
127
|
-
while (win.should_close(win.win()) == GL_FALSE) {
|
128
|
-
std::this_thread::sleep_for(std::chrono::seconds(1));
|
129
|
-
auto curr = std::chrono::system_clock::now();
|
130
|
-
// 処理に要した時間をミリ秒に変換。
|
131
|
-
auto elapsed =
|
132
|
-
std::chrono::duration_cast<std::chrono::milliseconds>(curr - pre);
|
133
|
-
pre = curr;
|
134
|
-
lag = lag + elapsed;
|
135
|
-
|
136
|
-
// 画面をクリア。
|
137
|
-
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
138
|
-
// 変換行列の初期化。
|
139
|
-
glLoadIdentity();
|
140
|
-
|
141
|
-
/* インプット */
|
142
|
-
|
143
|
-
// 現在のウィンドウの大きさを取得。
|
144
|
-
int wid, hei;
|
145
|
-
glfwGetFramebufferSize(win.win(), &wid, &hei);
|
146
|
-
|
147
|
-
// ESCキーで終了。
|
148
|
-
if (glfwGetKey(win.win(), GLFW_KEY_ESCAPE) == GLFW_PRESS) {
|
149
|
-
break;
|
150
|
-
};
|
151
|
-
|
152
|
-
while (lag >= MS_PER_UPDATE) {
|
153
|
-
|
154
|
-
/* 更新 */
|
155
|
-
|
156
|
-
scene.update(win);
|
157
|
-
};
|
158
|
-
|
159
|
-
/* 描画 */
|
160
|
-
|
161
|
-
scene.render(win);
|
162
|
-
|
163
|
-
glViewport(0, 0, wid, hei);
|
164
|
-
lag -= MS_PER_UPDATE;
|
165
|
-
};
|
166
|
-
};
|
167
|
-
|
168
|
-
```
|
169
|
-
|
170
|
-
```c++
|
171
|
-
#pragma once
|
172
|
-
|
173
|
-
#include <GL/glew.h>
|
174
|
-
#include <GLFW/glfw3.h>
|
175
|
-
#include <iostream>
|
176
|
-
#include <vector>
|
177
|
-
|
178
|
-
// ウィンドウ関連の処理。
|
179
|
-
class Window {
|
180
|
-
// ウィンドウのポインタの入れ物。
|
181
|
-
GLFWwindow *win_;
|
182
|
-
// ウィンドウのサイズ。
|
183
|
-
std::vector<GLfloat> size_;
|
184
|
-
// 図形の正規化デバイス座標系上での位置。
|
185
|
-
std::vector<GLfloat> pos_;
|
186
|
-
// ワールド座標系に対するデバイス座標系の拡大率。
|
187
|
-
GLfloat scale_;
|
188
|
-
// キーボードの状態。
|
189
|
-
int key_status_;
|
190
|
-
|
191
|
-
public:
|
192
|
-
// コンストラクタ。
|
193
|
-
Window(int wid = 640, int hei = 480, const char *title = "MendelsEngine")
|
194
|
-
: win_(glfwCreateWindow(wid, hei, title, NULL, NULL)), scale_(100.0f),
|
195
|
-
key_status_(GLFW_RELEASE) {
|
196
|
-
|
197
|
-
// 作成したウィンドウをOpenGLの処理対象にする。
|
198
|
-
glfwMakeContextCurrent(win_);
|
199
|
-
|
200
|
-
// GLEW を初期化する。
|
201
|
-
glewExperimental = GL_TRUE;
|
202
|
-
if (glewInit() != GLEW_OK) {
|
203
|
-
// GLEW の初期化に失敗した。
|
204
|
-
std::cerr << "Can't initialize GLEW" << std::endl;
|
205
|
-
};
|
206
|
-
|
207
|
-
// 垂直同期のタイミングを待つ。
|
208
|
-
glfwSwapInterval(1);
|
209
|
-
// ウィンドウのサイズ変更時に呼び出す処理の登録。
|
210
|
-
glfwSetWindowSizeCallback(win_, &resize);
|
211
|
-
// マウスホイール操作時に呼び出す処理の登録。
|
212
|
-
glfwSetScrollCallback(win_, &wheel);
|
213
|
-
// キーボード操作時に呼び出す処理の登録。
|
214
|
-
glfwSetKeyCallback(win_, &keyboard);
|
215
|
-
// このインスタンスの this ポインタを記録しておく。
|
216
|
-
glfwSetWindowUserPointer(win_, this);
|
217
|
-
// 開いたウィンドウの初期設定。
|
218
|
-
resize(win_, wid, hei);
|
219
|
-
};
|
220
|
-
|
221
|
-
// デストラクタ。
|
222
|
-
virtual ~Window() { glfwDestroyWindow(win_); }
|
223
|
-
|
224
|
-
// メンバ関数。
|
225
|
-
int should_close(GLFWwindow *win) const;
|
226
|
-
void swap_buffers(GLFWwindow *win, int key_status);
|
227
|
-
// ウィンドウのサイズ変更時の処理。
|
228
|
-
static void resize(GLFWwindow *win, int wid, int hei){
|
229
|
-
// ウィンドウ全体をビューポートに設定する。
|
230
|
-
glViewport(0, 0, wid, hei);
|
231
|
-
// このインスタンスの this ポインタを得る。
|
232
|
-
Window *instance(static_cast<Window *>(glfwGetWindowUserPointer(win)));
|
233
|
-
if (instance != NULL) {
|
234
|
-
// 開いたウィンドウのサイズを保存する。
|
235
|
-
GLfloat wid0 = static_cast<GLfloat>(wid);
|
236
|
-
GLfloat hei0 = static_cast<GLfloat>(hei);
|
237
|
-
instance->size(0, wid0);
|
238
|
-
instance->size(1, hei0);
|
239
|
-
};
|
240
|
-
};
|
241
|
-
// マウスホイール操作時の処理。
|
242
|
-
static void wheel(GLFWwindow *win, double x, double y){
|
243
|
-
// このインスタンスの this ポインタを得る。
|
244
|
-
Window *const instance(static_cast<Window *>(glfwGetWindowUserPointer(win)));
|
245
|
-
if (instance != NULL) {
|
246
|
-
// ワールド座標系に対するデバイス座標系の拡大率を更新する。
|
247
|
-
GLfloat scale0 = instance->scale() + static_cast<GLfloat>(y);
|
248
|
-
instance->scale(scale0);
|
249
|
-
};
|
250
|
-
};
|
251
|
-
// キーボード操作時の処理。
|
252
|
-
static void keyboard(GLFWwindow *win, int action, int key = -1,
|
253
|
-
int scancode = -1, int mods = -1){
|
254
|
-
// このインスタンスの this ポインタを得る。
|
255
|
-
Window *const instance(static_cast<Window *>(glfwGetWindowUserPointer(win)));
|
256
|
-
if (instance != NULL) {
|
257
|
-
// キーの状態を保存する。
|
258
|
-
instance->key_status(action);
|
259
|
-
};
|
260
|
-
};
|
261
|
-
|
262
|
-
// アクセサ。
|
263
|
-
GLFWwindow *win() { return win_; };
|
264
|
-
|
265
|
-
std::vector<GLfloat> size() { return size_; };
|
266
|
-
GLfloat size(int i) { return size_[i]; };
|
267
|
-
void size(int i, GLfloat &glf) { size_[i] = glf; };
|
268
|
-
|
269
|
-
std::vector<GLfloat> pos() { return pos_; };
|
270
|
-
GLfloat pos(int i) { return pos_[i]; };
|
271
|
-
void pos(int i, GLfloat &glf) { pos_[i] = glf; };
|
272
|
-
|
273
|
-
GLfloat scale() { return scale_; };
|
274
|
-
void scale(GLfloat &glf) { scale_ = glf; };
|
275
|
-
|
276
|
-
int key_status() { return key_status_; };
|
277
|
-
void key_status(int &i) { key_status_ = i; };
|
278
|
-
};
|
279
|
-
```
|
1
|
+
### 問題(Problem)
|
2
|
+
* glfw3を使って、ウィンドウを表示させたいのですが、
|
3
|
+
|
4
|
+
ERROR: Setting <GLFWContentView: 0x1007508a0> as the first responder for window <GLFWWindow: 0x10072f620>, but it is in a different window ((null))! This would eventually crash when the view is freed. The first responder will be set to nil.
|
5
|
+
|
6
|
+
というエラーが出て、表示する途中で落ちてしまいます。
|
7
|
+
どうすれば解決できるでしょうか?
|
8
|
+
|
9
|
+
* My program has a error with glfw3 window. The error is that
|
10
|
+
|
11
|
+
ERROR: Setting <GLFWContentView: 0x1007508a0> as the first responder for window <GLFWWindow: 0x10072f620>, but it is in a different window ((null))! This would eventually crash when the view is freed. The first responder will be set to nil.
|
12
|
+
|
13
|
+
How can I deal with it?
|
14
|
+
|
15
|
+
### 発生している問題・エラーメッセージ(Error)
|
16
|
+
|
17
|
+
```
|
18
|
+
Main[74526:7122089] [General] ERROR: Setting <GLFWContentView: 0x1007508a0> as the first responder for window <GLFWWindow: 0x10072f620>, but it is in a different window ((null))! This would eventually crash when the view is freed. The first responder will be set to nil.
|
19
|
+
(
|
20
|
+
0 AppKit 0x00007fff5520752e -[NSWindow _validateFirstResponder:] + 578
|
21
|
+
1 AppKit 0x00007fff5494ea58 -[NSWindow _setFirstResponder:] + 31
|
22
|
+
2 AppKit 0x00007fff549ed17d -[NSWindow _realMakeFirstResponder:] + 448
|
23
|
+
3 Main 0x0000000100055003 createNativeWindow + 1187
|
24
|
+
4 Main 0x000000010005490f _glfwPlatformCreateWindow + 63
|
25
|
+
5 Main 0x000000010004d167 glfwCreateWindow + 887
|
26
|
+
6 Main 0x000000010000caa1 _ZN6WindowC2EiiPKc + 97
|
27
|
+
7 Main 0x0000000100008e59 _ZN6WindowC1EiiPKc + 41
|
28
|
+
8 Main 0x000000010000855c main + 156
|
29
|
+
9 libdyld.dylib 0x00007fff7ebc4115 start + 1
|
30
|
+
)
|
31
|
+
|
32
|
+
```
|
33
|
+
|