Skip to content

Commit 25e445a

Browse files
committed
Fix Windows crash: remove duplicate glClear/glfwSwapBuffers in init
1 parent 0649952 commit 25e445a

2 files changed

Lines changed: 1 addition & 46 deletions

File tree

mode/CppMode.jar

-982 Bytes
Binary file not shown.

src/Processing.cpp

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3332,9 +3332,6 @@ void PApplet::run(){
33323332
::std::srand((unsigned)::std::time(nullptr));
33333333
initPerlin(0); // initialize noise table with default seed
33343334

3335-
#ifdef _WIN32
3336-
MessageBoxA(NULL, "Before glfwInit", "Debug-1", MB_OK);
3337-
#endif
33383335
if(!glfwInit()){
33393336
fprintf(stderr, "[ERR] glfwInit() failed. Make sure libglfw3.dll is next to ide.exe\n");
33403337
#ifdef _WIN32
@@ -3361,13 +3358,6 @@ void PApplet::run(){
33613358
glfwWindowHint(GLFW_RESIZABLE,isResizable?GLFW_TRUE:GLFW_FALSE);
33623359
glfwWindowHint(GLFW_SAMPLES,4);
33633360
glfwWindowHint(GLFW_STENCIL_BITS,8);
3364-
// Request OpenGL 3.3 compatibility profile
3365-
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
3366-
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
3367-
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE);
3368-
#ifdef _WIN32
3369-
MessageBoxA(NULL, "Before glfwCreateWindow", "Debug0", MB_OK);
3370-
#endif
33713361
gWindow=glfwCreateWindow(winWidth,winHeight,g_sketchName.c_str(),nullptr,nullptr);
33723362
if(!gWindow){
33733363
const char* err="unknown"; (void)err;
@@ -3412,13 +3402,7 @@ void PApplet::run(){
34123402
});
34133403
glfwMakeContextCurrent(gWindow);
34143404
glewExperimental = GL_TRUE;
3415-
#ifdef _WIN32
3416-
MessageBoxA(NULL, "Before glewInit", "Debug1", MB_OK);
3417-
#endif
34183405
GLenum glewErr = glewInit();
3419-
#ifdef _WIN32
3420-
MessageBoxA(NULL, "After glewInit", "Debug2", MB_OK);
3421-
#endif
34223406
if(glewErr != GLEW_OK){
34233407
#ifdef _WIN32
34243408
char msg[256]; snprintf(msg,sizeof(msg),"glewInit() failed: %s", glewGetErrorString(glewErr));
@@ -3433,38 +3417,17 @@ void PApplet::run(){
34333417
if(phongProg){glDeleteProgram(phongProg);phongProg=0;}
34343418
glEnable(GL_BLEND);glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
34353419
glEnable(GL_DEPTH_TEST);
3436-
#ifdef _WIN32
3437-
MessageBoxA(NULL, "After GL enable calls", "Debug3", MB_OK);
3438-
#endif
3439-
#ifdef _WIN32
3440-
MessageBoxA(NULL, "Before getFramebufferSize", "Debug4x", MB_OK);
3441-
#endif
34423420
// Don't call setProjection here -- let size() in this->setup() do it
34433421
// with the correct dimensions. Calling it now with winWidth=640,winHeight=480
34443422
// (defaults) would set the wrong ortho before this->setup() changes the size.
34453423
{int fw,fh;glfwGetFramebufferSize(gWindow,&fw,&fh);pixelWidth=fw;pixelHeight=fh;fbW=fw>0?fw:logicalW;fbH=fh>0?fh:logicalH;}
3446-
#ifdef _WIN32
3447-
MessageBoxA(NULL, "After getFramebufferSize", "Debug4y", MB_OK);
3448-
#endif
34493424

34503425
// Enable sticky keys/buttons: GLFW will keep state as PRESSED until polled,
34513426
// Clear both buffers once at startup so the sketch starts with
34523427
// a known clean state (no GPU garbage in either buffer).
3453-
#ifdef _WIN32
3454-
MessageBoxA(NULL, "Before glClearColor", "Debug4a", MB_OK);
3455-
#endif
34563428
glClearColor(0.8f,0.8f,0.8f,1);
3457-
#ifdef _WIN32
3458-
MessageBoxA(NULL, "Before first glClear", "Debug4b", MB_OK);
3459-
#endif
34603429
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
3461-
#ifdef _WIN32
3462-
MessageBoxA(NULL, "Before glfwSwapBuffers", "Debug4c", MB_OK);
3463-
#endif
34643430
glfwSwapBuffers(gWindow);
3465-
#ifdef _WIN32
3466-
MessageBoxA(NULL, "After glfwSwapBuffers", "Debug4e", MB_OK);
3467-
#endif
34683431
// preventing missed inputs on Windows where events can arrive between polls.
34693432
glfwSetInputMode(gWindow, GLFW_STICKY_KEYS, GLFW_TRUE);
34703433
glfwSetInputMode(gWindow, GLFW_STICKY_MOUSE_BUTTONS, GLFW_TRUE);
@@ -3477,9 +3440,6 @@ void PApplet::run(){
34773440
glfwSetWindowSizeCallback(gWindow, winsize_cb);
34783441
glfwSetWindowFocusCallback(gWindow, focus_cb);
34793442
glfwSetWindowPosCallback(gWindow, winpos_cb);
3480-
#ifdef _WIN32
3481-
MessageBoxA(NULL, "After callbacks", "Debug4f", MB_OK);
3482-
#endif
34833443
focused=(glfwGetWindowAttrib(gWindow,GLFW_FOCUSED)==GLFW_TRUE);
34843444

34853445
// Auto-load default.ttf from project root as the default font
@@ -3532,10 +3492,7 @@ void PApplet::run(){
35323492
}
35333493
}
35343494

3535-
#ifdef _WIN32
3536-
MessageBoxA(NULL, "Before glfwFocusWindow", "Debug5", MB_OK);
3537-
#endif
3538-
glfwFocusWindow(gWindow); // ensure input focus on Windows
3495+
glfwFocusWindow(gWindow);
35393496

35403497
// Settle loop: poll+swap several times BEFORE this->setup() runs so i3/tiling WMs
35413498
// fully resize the window first. winsize_cb fires during these polls and
@@ -3547,8 +3504,6 @@ void PApplet::run(){
35473504
glClearColor(0.8f,0.8f,0.8f,1);
35483505
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
35493506
glfwSwapBuffers(gWindow);
3550-
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
3551-
glfwSwapBuffers(gWindow);
35523507
#ifndef __EMSCRIPTEN__
35533508
for (int _settle = 0; _settle < 5; _settle++) {
35543509
glClearColor(0.8f,0.8f,0.8f,1);

0 commit comments

Comments
 (0)