{"action":"created","issue":{"url":"https://api.github.com/repos/leadedge/Spout2/issues/15","repository_url":"https://api.github.com/repos/leadedge/Spout2","labels_url":"https://api.github.com/repos/leadedge/Spout2/issues/15/labels{/name}","comments_url":"https://api.github.com/repos/leadedge/Spout2/issues/15/comments","events_url":"https://api.github.com/repos/leadedge/Spout2/issues/15/events","html_url":"https://github.com/leadedge/Spout2/issues/15","id":154017998,"number":15,"title":"Sometime SpoutSharedMemory::Unlock() assert(m_lockCount >= 0)","user":{"login":"Qlex42","id":811662,"avatar_url":"https://avatars.githubusercontent.com/u/811662?v=3","gravatar_id":"","url":"https://api.github.com/users/Qlex42","html_url":"https://github.com/Qlex42","followers_url":"https://api.github.com/users/Qlex42/followers","following_url":"https://api.github.com/users/Qlex42/following{/other_user}","gists_url":"https://api.github.com/users/Qlex42/gists{/gist_id}","starred_url":"https://api.github.com/users/Qlex42/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Qlex42/subscriptions","organizations_url":"https://api.github.com/users/Qlex42/orgs","repos_url":"https://api.github.com/users/Qlex42/repos","events_url":"https://api.github.com/users/Qlex42/events{/privacy}","received_events_url":"https://api.github.com/users/Qlex42/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-05-10T14:18:09Z","updated_at":"2016-05-11T07:13:01Z","closed_at":null,"body":"Hi\r\nMy application is multi-threaded  (gui and opengl have different threads) \r\nI'm also using shared multi opengl context.\r\nI avoid Spout API concurrent calls with a custom global mutex.\r\nI'm using the last Master branch version of Spout2\r\n\r\nIn very rare case, SpoutSharedMemory::Unlock() assert(m_lockCount >= 0) \r\nin SpoutSharedMemory.cpp at line 235\r\nThis is because spoutMemoryShare::LockSenderMemory() call SpoutSharedMemory::Unlock() when SpoutSharedMemory::Lock() fail in SpoutSenderMemory.cpp at line 196. \r\n\r\nAs other Lock() callers, this function should not call Unlock() when Lock() fail. This made the m_lockCount value negative and introduce further problems...\r\n\r\nFrom a general point of view, I'm not convicted about the needs of the m_lockCount variable:\r\nMSDN ReleaseMutex documentation says that: A thread can specify a mutex that it already owns in a call to one of the wait functions without blocking its execution. This prevents a thread from deadlocking itself while waiting for a mutex that it already owns. However, to release its ownership, the thread must call ReleaseMutex one time for each time that it obtained ownership (either through CreateMutex or a wait function).\r\n\r\nThanks for your interest about this issue.\r\n\r\nRegards,"},"comment":{"url":"https://api.github.com/repos/leadedge/Spout2/issues/comments/218380287","html_url":"https://github.com/leadedge/Spout2/issues/15#issuecomment-218380287","issue_url":"https://api.github.com/repos/leadedge/Spout2/issues/15","id":218380287,"user":{"login":"leadedge","id":7351229,"avatar_url":"https://avatars.githubusercontent.com/u/7351229?v=3","gravatar_id":"","url":"https://api.github.com/users/leadedge","html_url":"https://github.com/leadedge","followers_url":"https://api.github.com/users/leadedge/followers","following_url":"https://api.github.com/users/leadedge/following{/other_user}","gists_url":"https://api.github.com/users/leadedge/gists{/gist_id}","starred_url":"https://api.github.com/users/leadedge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leadedge/subscriptions","organizations_url":"https://api.github.com/users/leadedge/orgs","repos_url":"https://api.github.com/users/leadedge/repos","events_url":"https://api.github.com/users/leadedge/events{/privacy}","received_events_url":"https://api.github.com/users/leadedge/received_events","type":"User","site_admin":false},"created_at":"2016-05-11T07:13:01Z","updated_at":"2016-05-11T07:13:01Z","body":"Thanks for tracking this down so that it is an easy fix. I checked through \"SpoutSenderNames.cpp\" where the memory map locks are most frequently used and it is OK.\r\n\r\nThe purpose of the \"SpoutMemoryShare\" class is to provide a backup when texture sharing fails, so in most cases it will not be used.\r\n\r\nI would seek advice about the \"SpoutSharedMemory\" class from the author Malcolm Bechard, but if using the m_lockCount variable is causing no harm I would leave it alone.\r\n"}}