Bug 1634044 Comment 13 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

Notes to self: I modified the code to keep things going like this:
```c++
 void MouseCursorMonitorWin::Capture() {
-  assert(IsGUIThread(false));
+  CURSORINFO cursor_info;
+  if (!IsGUIThread(true)) {
+    RTC_LOG_F(LS_ERROR) << "No GUIThread info.";
+    return;
+  }
   assert(callback_);
```
...and instrumented like this (pardon the triple printfs, it was in response to pilot trouble getting output, but this matters at the end):
```c++
 void PlatformUIThread::Run() {
+  printf("JIB: HERE. %lu\n", GetLastError());
+  fprintf(stderr, "JIB: ERRHERE. %lu\n", GetLastError());
+  fprintf(stdout, "JIB: STDHERE. %lu\n", GetLastError());
   RTC_CHECK(InternalInit());  // always evaluates
```
```c++
@@ -30,26 +30,41 @@ bool PlatformUIThread::InternalInit() {
     HMODULE hModule = GetModuleHandle(NULL);
     if (!GetClassInfoW(hModule, kThreadWindow, &wc)) {
       ZeroMemory(&wc, sizeof(WNDCLASSW));
       wc.hInstance = hModule;
       wc.lpfnWndProc = EventWindowProc;
       wc.lpszClassName = kThreadWindow;
       RegisterClassW(&wc);
     }
+    printf("JIB: ZERO. %p\n", hwnd_);
+    fprintf(stderr, "JIB: ERRZERO. %p\n", hwnd_);
+    fprintf(stdout, "JIB: STDZERO. %p\n", hwnd_);
     hwnd_ = CreateWindowW(kThreadWindow, L"", 0, 0, 0, 0, 0, NULL, NULL,
                           hModule, NULL);
+    if (!hwnd_) {
+      printf("JIB: last error = %lu\n", GetLastError());
+      IsGUIThread(true);
+      hwnd_ = CreateWindowW(kThreadWindow, L"", 0, 0, 0, 0, 0, NULL, NULL,
+        hModule, NULL);
+      if (!hwnd_) {
+        printf("JIB: Retry last error = %lu\n", GetLastError());
+      }
+    }
     RTC_DCHECK(hwnd_);
     SetPropW(hwnd_, kThisProperty, this);

     if (timeout_) {
       // if someone set the timer before we started
       RequestCallbackTimer(timeout_);
     }
   }
+  printf("JIB: RETURN. %p\n", hwnd_);
+  fprintf(stderr, "JIB: ERRRETURN. %p\n", hwnd_);
+  fprintf(stdout, "JIB: STDRETURN. %p\n", hwnd_);
   return !!hwnd_;
 }
```
I then wiggled the sliders (which stops+starts capture a lot) until it provoked the RTC_CHECK(InternalInit()) to crash
```
tail...
JIB: ZERO. 0000000000000000
JIB: ERRZERO. 0000000000000000
JIB: STDZERO. 0000000000000000
JIB: RETURN. 000000000044067E
JIB: ERRRETURN. 000000000044067E
JIB: STDRETURN. 000000000044067E
JIB: HERE. 0
JIB: ERRHERE. 0
JIB: STDHERE. 0
JIB: RETURN. 000000000044067E
JIB: ERRRETURN. 000000000044067E
JIB: STDRETURN. 000000000044067E
JIB: HERE. 0
JIB: ERRHERE. 0
JIB: STDHERE. 0
JIB: ZERO. 0000000000000000
JIB: ERRZERO. 0000000000000000
JIB: STDZERO. 0000000000000000
JIB: RETURN. 000000000045067E
JIB: ERRRETURN. 000000000045067E
JIB: STDRETURN. 000000000045067E
JIB: HERE. 0
JIB: ERRHERE. 0
JIB: STDHERE. 0
JIB: ZERO. 0000000000000000
JIB: ERRZERO. 0000000000000000
JIB: STDZERO. 0000000000000000
JIB: RETURN. 000000000046067E
JIB: ERRRETURN. 000000000046067E
JIB: STDRETURN. 000000000046067E
JIB: HERE. 0
JIB: ERRHERE. 0
JIB: STDHERE. 0
JIB: RETURN. 000000000046067E
JIB: ERRRETURN. 0000000000000000
JIB: STDRETURN. 0000000000000000


#
# Fatal error in c:/moz/mozilla-central/dom/media/systemservices/video_engine/platform_uithread.cc, line 110
# last system error: 0
# Check failed: InternalInit()
#
#
```
Looking at the last 3 lines before the crash, it looks like `hwnd_` got cleared in between adjacent printf statements, suggesting a race.

(this is without the patch in this bug fyi)
Notes to self: I modified the code to keep things going like this:
```c++
 void MouseCursorMonitorWin::Capture() {
-  assert(IsGUIThread(false));
+  if (!IsGUIThread(true)) {
+    RTC_LOG_F(LS_ERROR) << "No GUIThread info.";
+    return;
+  }
   assert(callback_);
```
...and instrumented like this (pardon the triple printfs, it was in response to pilot trouble getting output, but this matters at the end):
```c++
 void PlatformUIThread::Run() {
+  printf("JIB: HERE. %lu\n", GetLastError());
+  fprintf(stderr, "JIB: ERRHERE. %lu\n", GetLastError());
+  fprintf(stdout, "JIB: STDHERE. %lu\n", GetLastError());
   RTC_CHECK(InternalInit());  // always evaluates
```
```c++
@@ -30,26 +30,41 @@ bool PlatformUIThread::InternalInit() {
     HMODULE hModule = GetModuleHandle(NULL);
     if (!GetClassInfoW(hModule, kThreadWindow, &wc)) {
       ZeroMemory(&wc, sizeof(WNDCLASSW));
       wc.hInstance = hModule;
       wc.lpfnWndProc = EventWindowProc;
       wc.lpszClassName = kThreadWindow;
       RegisterClassW(&wc);
     }
+    printf("JIB: ZERO. %p\n", hwnd_);
+    fprintf(stderr, "JIB: ERRZERO. %p\n", hwnd_);
+    fprintf(stdout, "JIB: STDZERO. %p\n", hwnd_);
     hwnd_ = CreateWindowW(kThreadWindow, L"", 0, 0, 0, 0, 0, NULL, NULL,
                           hModule, NULL);
+    if (!hwnd_) {
+      printf("JIB: last error = %lu\n", GetLastError());
+      IsGUIThread(true);
+      hwnd_ = CreateWindowW(kThreadWindow, L"", 0, 0, 0, 0, 0, NULL, NULL,
+        hModule, NULL);
+      if (!hwnd_) {
+        printf("JIB: Retry last error = %lu\n", GetLastError());
+      }
+    }
     RTC_DCHECK(hwnd_);
     SetPropW(hwnd_, kThisProperty, this);

     if (timeout_) {
       // if someone set the timer before we started
       RequestCallbackTimer(timeout_);
     }
   }
+  printf("JIB: RETURN. %p\n", hwnd_);
+  fprintf(stderr, "JIB: ERRRETURN. %p\n", hwnd_);
+  fprintf(stdout, "JIB: STDRETURN. %p\n", hwnd_);
   return !!hwnd_;
 }
```
I then wiggled the sliders (which stops+starts capture a lot) until it provoked the RTC_CHECK(InternalInit()) to crash
```
tail...
JIB: ZERO. 0000000000000000
JIB: ERRZERO. 0000000000000000
JIB: STDZERO. 0000000000000000
JIB: RETURN. 000000000044067E
JIB: ERRRETURN. 000000000044067E
JIB: STDRETURN. 000000000044067E
JIB: HERE. 0
JIB: ERRHERE. 0
JIB: STDHERE. 0
JIB: RETURN. 000000000044067E
JIB: ERRRETURN. 000000000044067E
JIB: STDRETURN. 000000000044067E
JIB: HERE. 0
JIB: ERRHERE. 0
JIB: STDHERE. 0
JIB: ZERO. 0000000000000000
JIB: ERRZERO. 0000000000000000
JIB: STDZERO. 0000000000000000
JIB: RETURN. 000000000045067E
JIB: ERRRETURN. 000000000045067E
JIB: STDRETURN. 000000000045067E
JIB: HERE. 0
JIB: ERRHERE. 0
JIB: STDHERE. 0
JIB: ZERO. 0000000000000000
JIB: ERRZERO. 0000000000000000
JIB: STDZERO. 0000000000000000
JIB: RETURN. 000000000046067E
JIB: ERRRETURN. 000000000046067E
JIB: STDRETURN. 000000000046067E
JIB: HERE. 0
JIB: ERRHERE. 0
JIB: STDHERE. 0
JIB: RETURN. 000000000046067E
JIB: ERRRETURN. 0000000000000000
JIB: STDRETURN. 0000000000000000


#
# Fatal error in c:/moz/mozilla-central/dom/media/systemservices/video_engine/platform_uithread.cc, line 110
# last system error: 0
# Check failed: InternalInit()
#
#
```
Looking at the last 3 lines before the crash, it looks like `hwnd_` got cleared in between adjacent printf statements, suggesting a race.

(this is without the patch in this bug fyi)
Notes to self: I modified the code to keep things going like this:
```c++
 void MouseCursorMonitorWin::Capture() {
-  assert(IsGUIThread(false));
+  if (!IsGUIThread(true)) {
+    RTC_LOG_F(LS_ERROR) << "No GUIThread info.";
+    return;
+  }
   assert(callback_);
```
...and instrumented like this (pardon the triple printfs, it was in response to pilot trouble getting output, but this matters at the end):
```c++
 void PlatformUIThread::Run() {
+  printf("JIB: HERE. %lu\n", GetLastError());
+  fprintf(stderr, "JIB: ERRHERE. %lu\n", GetLastError());
+  fprintf(stdout, "JIB: STDHERE. %lu\n", GetLastError());
   RTC_CHECK(InternalInit());  // always evaluates
```
```c++
@@ -30,26 +30,41 @@ bool PlatformUIThread::InternalInit() {
     HMODULE hModule = GetModuleHandle(NULL);
     if (!GetClassInfoW(hModule, kThreadWindow, &wc)) {
       ZeroMemory(&wc, sizeof(WNDCLASSW));
       wc.hInstance = hModule;
       wc.lpfnWndProc = EventWindowProc;
       wc.lpszClassName = kThreadWindow;
       RegisterClassW(&wc);
     }
+    printf("JIB: ZERO. %p\n", hwnd_);
+    fprintf(stderr, "JIB: ERRZERO. %p\n", hwnd_);
+    fprintf(stdout, "JIB: STDZERO. %p\n", hwnd_);
     hwnd_ = CreateWindowW(kThreadWindow, L"", 0, 0, 0, 0, 0, NULL, NULL,
                           hModule, NULL);
+    if (!hwnd_) {
+      printf("JIB: last error = %lu\n", GetLastError());
+      IsGUIThread(true);
+      hwnd_ = CreateWindowW(kThreadWindow, L"", 0, 0, 0, 0, 0, NULL, NULL,
+        hModule, NULL);
+      if (!hwnd_) {
+        printf("JIB: Retry last error = %lu\n", GetLastError());
+      }
+    }
     RTC_DCHECK(hwnd_);
     SetPropW(hwnd_, kThisProperty, this);

     if (timeout_) {
       // if someone set the timer before we started
       RequestCallbackTimer(timeout_);
     }
   }
+  printf("JIB: RETURN. %p\n", hwnd_);
+  fprintf(stderr, "JIB: ERRRETURN. %p\n", hwnd_);
+  fprintf(stdout, "JIB: STDRETURN. %p\n", hwnd_);
   return !!hwnd_;
 }
```
I then wiggled the sliders (which stops+starts capture a lot) until it provoked the `RTC_CHECK(InternalInit())` to crash
```
tail...
JIB: ZERO. 0000000000000000
JIB: ERRZERO. 0000000000000000
JIB: STDZERO. 0000000000000000
JIB: RETURN. 000000000044067E
JIB: ERRRETURN. 000000000044067E
JIB: STDRETURN. 000000000044067E
JIB: HERE. 0
JIB: ERRHERE. 0
JIB: STDHERE. 0
JIB: RETURN. 000000000044067E
JIB: ERRRETURN. 000000000044067E
JIB: STDRETURN. 000000000044067E
JIB: HERE. 0
JIB: ERRHERE. 0
JIB: STDHERE. 0
JIB: ZERO. 0000000000000000
JIB: ERRZERO. 0000000000000000
JIB: STDZERO. 0000000000000000
JIB: RETURN. 000000000045067E
JIB: ERRRETURN. 000000000045067E
JIB: STDRETURN. 000000000045067E
JIB: HERE. 0
JIB: ERRHERE. 0
JIB: STDHERE. 0
JIB: ZERO. 0000000000000000
JIB: ERRZERO. 0000000000000000
JIB: STDZERO. 0000000000000000
JIB: RETURN. 000000000046067E
JIB: ERRRETURN. 000000000046067E
JIB: STDRETURN. 000000000046067E
JIB: HERE. 0
JIB: ERRHERE. 0
JIB: STDHERE. 0
JIB: RETURN. 000000000046067E
JIB: ERRRETURN. 0000000000000000
JIB: STDRETURN. 0000000000000000


#
# Fatal error in c:/moz/mozilla-central/dom/media/systemservices/video_engine/platform_uithread.cc, line 110
# last system error: 0
# Check failed: InternalInit()
#
#
```
Looking at the last 3 lines before the crash, it looks like `hwnd_` got cleared in between adjacent printf statements, suggesting a race.

(this is without the patch in this bug fyi)

Back to Bug 1634044 Comment 13