{"action":"created","issue":{"url":"https://api.github.com/repos/openframeworks/openFrameworks/issues/3748","labels_url":"https://api.github.com/repos/openframeworks/openFrameworks/issues/3748/labels{/name}","comments_url":"https://api.github.com/repos/openframeworks/openFrameworks/issues/3748/comments","events_url":"https://api.github.com/repos/openframeworks/openFrameworks/issues/3748/events","html_url":"https://github.com/openframeworks/openFrameworks/issues/3748","id":66670363,"number":3748,"title":"Crash when unloading programmable renderer's shaders on windows","user":{"login":"admsyn","id":609318,"avatar_url":"https://avatars.githubusercontent.com/u/609318?v=3","gravatar_id":"","url":"https://api.github.com/users/admsyn","html_url":"https://github.com/admsyn","followers_url":"https://api.github.com/users/admsyn/followers","following_url":"https://api.github.com/users/admsyn/following{/other_user}","gists_url":"https://api.github.com/users/admsyn/gists{/gist_id}","starred_url":"https://api.github.com/users/admsyn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/admsyn/subscriptions","organizations_url":"https://api.github.com/users/admsyn/orgs","repos_url":"https://api.github.com/users/admsyn/repos","events_url":"https://api.github.com/users/admsyn/events{/privacy}","received_events_url":"https://api.github.com/users/admsyn/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/openframeworks/openFrameworks/labels/visual%20studio","name":"visual studio","color":"ba4eba"},{"url":"https://api.github.com/repos/openframeworks/openFrameworks/labels/windows","name":"windows","color":"244569"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-04-06T18:18:54Z","updated_at":"2015-04-06T19:00:58Z","closed_at":null,"body":"I'm not great at debugging via VS2012, so most of this is just speculation, apologies.\r\n\r\nWhen exiting a relatively simple app on Windows, I get `System.AccessViolationException` thrown on `glDetachShader` in the static `releaseShader(...)` in ofShader. This is being triggered by the destructor of ofGLProgrammableRenderer, cleaning up its shaders. It doesn't seem to matter which shader it attempts to unload, if I manually put `whateverShader.unload()` in the programmable renderer's destructor, it fails on that line.\r\n\r\nThe thread being reported by VS is not the main thread, but seems to be a dynamic something-or-other generated by the atexit handler (again I'm not really familiar with VS :) ).\r\n\r\n![shader-unload-trace](https://cloud.githubusercontent.com/assets/609318/7009245/e7c47370-dc66-11e4-9ea4-d33026d637b4.png)\r\n\r\ncontents of `this` as of destructor (ofGLProgrammableRenderer)\r\n```\r\nthis\r\n0x065d3008 {circlePolyline={...} circleMesh={...} triangleMesh={...} ...}\r\n    ofBaseGLRenderer: {...}\r\n    TYPE: \"ProgrammableGL\"\r\n    circlePolyline: {points=[21]({x=1.00000000 y=0.000000000 z=0.000000000 },{x=0.951056540 y=0.309017003 z=0.000000000 },{x=0.809017003 y=0.587785244 z=0.000000000 },{x=0.587785244 y=0.809017003 z=0.000000000 },{x=0.309016973 y=0.951056540 z=0.000000000 },{x=-4.37113883e-008 y=1.00000000 z=0.000000000 },{x=-0.309017032 y=0.951056480 z=0.000000000 },{x=-0.587785184 y=0.809017003 z=0.000000000 },{x=-0.809017062 y=0.587785184 z=0.000000000 },{x=-0.951056600 y=0.309016794 z=0.000000000 },{x=-1.00000000 y=-3.25841370e-007 z=0.000000000 },{x=-0.951056361 y=-0.309017420 z=0.000000000 },{x=-0.809016645 y=-0.587785721 z=0.000000000 },{x=-0.587784708 y=-0.809017420 z=0.000000000 },{x=-0.309016198 y=-0.951056778 z=0.000000000 },{x=9.65599156e-007 y=-1.00000000 z=0.000000000 },{x=0.309018046 y=-0.951056182 z=0.000000000 },{x=0.587786257 y=-0.809016287 z=0.000000000 },{x=0.809017777 y=-0.587784171 z=0.000000000 },{x=0.951056957 y=-0.309015602 z=0.000000000 },{x=1.00000000 y=1.74845553e-007 z=0.000000000 }) rightVector={..\r\n.} lengths=[0]() ...}\r\n    circleMesh: {vertices=[21]({x=1.00000000 y=0.000000000 z=0.000000000 },{x=0.951056540 y=0.309017003 z=0.000000000 },{x=0.809017003 y=0.587785244 z=0.000000000 },{x=0.587785244 y=0.809017003 z=0.000000000 },{x=0.309016973 y=0.951056540 z=0.000000000 },{x=-4.37113883e-008 y=1.00000000 z=0.000000000 },{x=-0.309017032 y=0.951056480 z=0.000000000 },{x=-0.587785184 y=0.809017003 z=0.000000000 },{x=-0.809017062 y=0.587785184 z=0.000000000 },{x=-0.951056600 y=0.309016794 z=0.000000000 },{x=-1.00000000 y=-3.25841370e-007 z=0.000000000 },{x=-0.951056361 y=-0.309017420 z=0.000000000 },{x=-0.809016645 y=-0.587785721 z=0.000000000 },{x=-0.587784708 y=-0.809017420 z=0.000000000 },{x=-0.309016198 y=-0.951056778 z=0.000000000 },{x=9.65599156e-007 y=-1.00000000 z=0.000000000 },{x=0.309018046 y=-0.951056182 z=0.000000000 },{x=0.587786257 y=-0.809016287 z=0.000000000 },{x=0.809017777 y=-0.587784171 z=0.000000000 },{x=0.951056957 y=-0.309015602 z=0.000000000 },{x=1.00000000 y=1.74845553e-007 z=0.000000000 }) colors=[0]() norm\r\nals=[0]() ...}\r\n    triangleMesh: {vertices=[3]({x=0.000000000 y=0.000000000 z=0.000000000 },{x=0.000000000 y=0.000000000 z=0.000000000 },{x=0.000000000 y=0.000000000 z=0.000000000 }) colors=[0]() normals=[0]() ...}\r\n    rectMesh: {vertices=[4]({x=0.000000000 y=0.000000000 z=0.000000000 },{x=0.000000000 y=0.000000000 z=0.000000000 },{x=0.000000000 y=0.000000000 z=0.000000000 },{x=0.000000000 y=0.000000000 z=0.000000000 }) colors=[0]() normals=[0]() ...}\r\n    lineMesh: {vertices=[2]({x=0.000000000 y=0.000000000 z=0.000000000 },{x=0.000000000 y=0.000000000 z=0.000000000 }) colors=[0]() normals=[0]() ...}\r\n    meshVbo: {vaoID=0 vaoChanged=false indexAttribute={...} ...}\r\n    matrixStack: {vFlipped=true orientation=OF_ORIENTATION_DEFAULT currentViewport={...} ...}\r\n    bBackgroundAuto: true\r\n    major: 4\r\n    minor: 1\r\n    currentShader: 0x00000000 {program=??? bLoaded=??? shaders=[...]() ...}\r\n    verticesEnabled: true\r\n    colorsEnabled: false\r\n    texCoordsEnabled: true\r\n    normalsEnabled: true\r\n    bitmapStringEnabled: false\r\n    usingCustomShader: false\r\n    settingDefaultShader: false\r\n    currentTextureTarget: -1\r\n    wrongUseLoggedOnce: false\r\n    uniqueShader: false\r\n    currentMaterial: 0x00000000\r\n    alphaMaskTextureTarget: -1\r\n    currentStyle: {color={...} bgColor={...} polyMode=OF_POLY_WINDING_ODD ...}\r\n    styleHistory: [0]()\r\n    graphics3d: {renderer=0x065d3008 plane={...} sphere={...} ...}\r\n    bitmapFont: {pixels={...} texture={...} }\r\n    path: {commands=[0]() windingMode=OF_POLY_WINDING_ODD fillColor={...} ...}\r\n    window: 0x065ce4b8 {coreEvents={...} currentRenderer=shared_ptr {...} [0 strong refs] [default] settings={...} ...}\r\n    defaultTexRectColor: {program=1 bLoaded=true shaders=[2]((35633, 2),(35632, 17)) ...}\r\n    defaultTexRectNoColor: {program=3 bLoaded=true shaders=[2]((35633, 4),(35632, 18)) ...}\r\n    defaultTex2DColor: {program=7 bLoaded=true shaders=[2]((35633, 8),(35632, 20)) ...}\r\n    defaultTex2DNoColor: {program=11 bLoaded=true shaders=[2]((35633, 12),(35632, 22)) ...}\r\n    defaultNoTexColor: {program=9 bLoaded=true shaders=[2]((35633, 10),(35632, 21)) ...}\r\n    defaultNoTexNoColor: {program=13 bLoaded=true shaders=[2]((35633, 14),(35632, 23)) ...}\r\n    alphaMaskRectShader: {program=5 bLoaded=true shaders=[2]((35633, 6),(35632, 19)) ...}\r\n    alphaMask2DShader: {program=15 bLoaded=true shaders=[2]((35633, 16),(35632, 24)) ...}\r\n    bitmapStringShader: {program=25 bLoaded=true shaders=[2]((35633, 26),(35632, 27)) ...}\r\n    defaultUniqueShader: {program=0 bLoaded=false shaders=[0]() ...}\r\n    shaderPlanarYUY2: {program=0 bLoaded=false shaders=[0]() ...}\r\n    shaderNV12: {program=0 bLoaded=false shaders=[0]() ...}\r\n    shaderNV21: {program=0 bLoaded=false shaders=[0]() ...}\r\n    shaderPlanarYUV: {program=0 bLoaded=false shaders=[0]() ...}\r\n    shaderPlanarYUY2Rect: {program=0 bLoaded=false shaders=[0]() ...}\r\n    shaderNV12Rect: {program=0 bLoaded=false shaders=[0]() ...}\r\n    shaderNV21Rect: {program=0 bLoaded=false shaders=[0]() ...}\r\n    shaderPlanarYUVRect: {program=0 bLoaded=false shaders=[0]() ...}\r\n    framebufferIdStack: [0]()\r\n    defaultFramebufferId: 0\r\n    currentFramebufferId: 0\r\n```\r\n\r\nUsing the new `ofRunApp` syntax, as below:\r\n```\r\nint main( ){\r\n\tofGLFWWindowSettings settings;\r\n\tsettings.setGLVersion(4, 1);\r\n\tsettings.width = 1920;\r\n\tsettings.height = 1080;\r\n\t\r\n\tauto window = ofCreateWindow(settings);\r\n\tauto app = shared_ptr<ofBaseApp>(new ofApp);\r\n\tofRunApp(window, app);\r\n\tofRunMainLoop();\r\n}\r\n```\r\n\r\n**NOTE** I am doing some weird stuff right now, moving the OF app onto the CLR and embedding a WPF app as a child window. This crash was happening before I started doing all this, but if that's overly suspicious I'll see if I can boil it down to a simpler reproduction. It doesn't happen with a totally barebones ofApp.\r\n\r\nWindows 7, VS2012, current OF master as of posting."},"comment":{"url":"https://api.github.com/repos/openframeworks/openFrameworks/issues/comments/90198867","html_url":"https://github.com/openframeworks/openFrameworks/issues/3748#issuecomment-90198867","issue_url":"https://api.github.com/repos/openframeworks/openFrameworks/issues/3748","id":90198867,"user":{"login":"admsyn","id":609318,"avatar_url":"https://avatars.githubusercontent.com/u/609318?v=3","gravatar_id":"","url":"https://api.github.com/users/admsyn","html_url":"https://github.com/admsyn","followers_url":"https://api.github.com/users/admsyn/followers","following_url":"https://api.github.com/users/admsyn/following{/other_user}","gists_url":"https://api.github.com/users/admsyn/gists{/gist_id}","starred_url":"https://api.github.com/users/admsyn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/admsyn/subscriptions","organizations_url":"https://api.github.com/users/admsyn/orgs","repos_url":"https://api.github.com/users/admsyn/repos","events_url":"https://api.github.com/users/admsyn/events{/privacy}","received_events_url":"https://api.github.com/users/admsyn/received_events","type":"User","site_admin":false},"created_at":"2015-04-06T19:00:58Z","updated_at":"2015-04-06T19:00:58Z","body":"Hey Tim, I'm not doing anything with static shaders etc unless there's something tricky going on.\r\n\r\nI can trigger the crash \"on demand\" by putting (for example)\r\n```\r\nofGLProgrammableRenderer::~ofGLProgrammableRenderer() {\r\n  defaultTexRectColor.unload();\r\n  defaultTexRectNoColor.unload();\r\n}\r\n```\r\n..and it'll crash on unloading the 2nd shader, regardless of which one it is.\r\n\r\nThis all happens before `ofApp::exit()` happens, I was trying to hack my way around it temporarily by just nulling out the renderer in `ofApp::exit()` but no such luck."}}