Separate image width/height from popup width/height. SetPopupBuffer used _popupWidth and _popupHeight that were previously changed to the new values by SetPopupSizeAndPosition. Because of this, the handles in SetBuffer were not released which caused AccessViolationException