Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling ITfCompositionView.Dispose() too many. #18

Open
punigram opened this issue Aug 6, 2024 · 0 comments
Open

Calling ITfCompositionView.Dispose() too many. #18

punigram opened this issue Aug 6, 2024 · 0 comments

Comments

@punigram
Copy link

punigram commented Aug 6, 2024

Thank you for your very useful component. Because IME and TSF's informations is very rare.
It's hard to develop my original text input UI system if this component didn't exist.

I'm using ImeSharp as my original customized verison.
But I have a problem.
System.AccessViolationException happened when end composition timing.

Happened here:
TextStore.cs

        public Result RequestLock(TsfSharp.TsLfFlags dwLockFlags)

            hrSession = _sink.OnLockGranted(dwLockFlags);  // <<HERE

On ImeSharp.Demo the problem doesn't happened.
So I researched and found a bug(?).

TextStore.cs

      public void OnEndComposition(ITfCompositionView view)

          view.Dispose()
          foreach(var item in _compViews)
                item.Dispose();
         _comvVIews.Clear();

On windows TSF sample
https://github.com/microsoft/Windows-classic-samples/blob/7af17c73750469ed2b5732a49e5cb26cbb716094/Samples/Win7Samples/winui/tsf/tsfapp/context.cpp

In CTSFEditWnd::OnStartComposition() calling ITfCompositionView.AddRef()
In CTSFEditWnd::OnEndComposition() calling ITfCompositionView.Release()

COM object's reference counter are incremented and decremented.

But in TextStore.cs, No view.AddRef() calling but calling view.Dispose().
And also _compViews item's Dispose() called (I think it same ITfCompositionView object).
Dispose() calls Release() internally, so the reference counter unmatched.

I fixed it like this:

Adding OnStartComposition()

view.AddRef()

And remove OnUpdateComposition()

 _compViews.Add(view)

And replace OnEndComposition()

_compViews.Remove(view)
view.Dispose()

I don't know well sharpgen's COM convert system.
So I might be misunderstanding the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant