Skip to content

Commit 89807a8

Browse files
committed
create failsafe window for always maintaining reference to shared context, fixes runtime error when removing external window objects from patch if only one present
1 parent b300763 commit 89807a8

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/ofxVisualProgramming.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ void ofxVisualProgramming::setup(ofxImGui::Gui* _guiRef, string release){
159159
canvas.toggleOfCam();
160160
easyCam.enableOrtho();
161161

162+
// create failsafe window for always maintaining reference to shared context
163+
setupFailsafeWindow();
164+
162165
// RESET TEMP FOLDER
163166
resetTempFolder();
164167

@@ -187,6 +190,28 @@ void ofxVisualProgramming::setup(ofxImGui::Gui* _guiRef, string release){
187190

188191
}
189192

193+
//--------------------------------------------------------------
194+
void ofxVisualProgramming::setupFailsafeWindow(){
195+
ofGLFWWindowSettings settings;
196+
#if defined(OFXVP_GL_VERSION_MAJOR) && defined(OFXVP_GL_VERSION_MINOR)
197+
settings.setGLVersion(OFXVP_GL_VERSION_MAJOR,OFXVP_GL_VERSION_MINOR);
198+
#else
199+
settings.setGLVersion(3,2);
200+
#endif
201+
settings.shareContextWith = mainWindow;
202+
settings.decorated = true;
203+
settings.resizable = false;
204+
settings.visible = false;
205+
settings.setPosition(ofDefaultVec2(0,0));
206+
settings.setSize(10,10);
207+
208+
failsafeWindow = dynamic_pointer_cast<ofAppGLFWWindow>(ofCreateWindow(settings));
209+
failsafeWindow->setVerticalSync(false);
210+
failsafeWindow->setWindowPosition(0,0);
211+
212+
glfwSetWindowCloseCallback(failsafeWindow->getGLFWWindow(),GL_FALSE);
213+
}
214+
190215
//--------------------------------------------------------------
191216
void ofxVisualProgramming::update(){
192217

src/ofxVisualProgramming.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class ofxVisualProgramming : public pdsp::Wrapper {
6060

6161
void setRetina(bool retina);
6262
void setup(ofxImGui::Gui* guiRef = nullptr, string release="");
63+
void setupFailsafeWindow();
6364
void update();
6465
void updateCanvasViewport();
6566
void draw();
@@ -210,6 +211,8 @@ class ofxVisualProgramming : public pdsp::Wrapper {
210211
private:
211212
void audioProcess(float *input, int bufferSize, int nChannels);
212213

213-
mutable ofMutex vp_mutex;
214+
mutable ofMutex vp_mutex;
215+
216+
shared_ptr<ofAppGLFWWindow> failsafeWindow;
214217

215218
};

0 commit comments

Comments
 (0)