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

[Bug]: KryptonTreeView can throw exception on changing palette via KryptonManager #777

Closed
ZXBITLES opened this issue Jul 7, 2022 · 9 comments
Labels
bug Something isn't working completed This issue has been completed.
Milestone

Comments

@ZXBITLES
Copy link

ZXBITLES commented Jul 7, 2022

Describe the bug
Exception can be thrown in KryptonTreeView by method WndProc, when KryptonTreeView is visible (has expanded nodes) and palette changed.

To Reproduce

  1. Create a form with KryptonTreeView.
  2. Fill KryptonTreeView with some nodes.
  3. Add KryptonManager to a form.
  4. Start app.
  5. Expand few nodes in KryptonTreeView.
  6. Change palette via KryptonManager.
  7. Exception will be thrown in KryptonTreeView.cs at
    protected override void WndProc(ref Message m) {
    ...
    default:
    base.WndProc(ref m);
    break;
    ...
    }

Expected behavior
Exception shouldn't be thrown.

@ZXBITLES ZXBITLES added the bug Something isn't working label Jul 7, 2022
@PWagner1
Copy link
Contributor

PWagner1 commented Jul 7, 2022

@Smurf-IV Any ideas?

@ZXBITLES
Copy link
Author

ZXBITLES commented Jul 7, 2022

Well, I made a stupid workaround and its basically works:
default:
try
{
base.WndProc(ref m);
}
catch (Exception)
{ }
break;
I think, the reason is that some nodes are not available or not exist, so here we should write some kind if condition to check if it possible to call "base.WndProc(ref m);" or not, but I have no idea what to check...

By the way, for some reasons KryptonTreeView trying to collapse all the nodes when changing a palette, and when its done, then no exception is thrown.

@Smurf-IV
Copy link
Member

Smurf-IV commented Jul 8, 2022

@Smurf-IV Any ideas?

I have not seen this in the demo code

@Smurf-IV
Copy link
Member

Smurf-IV commented Jul 8, 2022

Well, I made a stupid workaround and its basically works: default: try { base.WndProc(ref m); } catch (Exception) { } break;

Where did you place this code ?

@ZXBITLES
Copy link
Author

ZXBITLES commented Jul 8, 2022

Where did you place this code ?

In "KryptonTreeView.cs" at "protected override void WndProc(ref Message m)".
By the way, I am creating KryptonManager dynamically on starting App before showing any forms and working with it to change a palette. So, KryptonManager does not lying on form. I don't think, that this is important, but must mention this.

@ZXBITLES
Copy link
Author

ZXBITLES commented Jul 8, 2022

Made a test - put KryptonManager to a form. The same result.
Besides of it, I see, that KryptonTreeView collapsing all the nodes on changing a palette. Could be that this can give an idea to find a reason.

@ZXBITLES
Copy link
Author

ZXBITLES commented Jul 8, 2022

Ok.
I think, that I got it!
Let me describe.
I created my own control which contains KryptonTreeView.
I am handling AfterSelect event for this KryptonTreeView.
The way to solve the problem is to check if e.Action equals to TreeViewAction.Unknown and exit a method in this case.
However, I do believe, that this is a bug and hope that my explanation can help to locate it.

"Bad" code:
Private Sub _TrvItems_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles _TrvItems.AfterSelect
...
End Sub

"Good" code:
Private Sub _TrvItems_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles _TrvItems.AfterSelect
If e.Action = TreeViewAction.Unknown Then Return
...
End Sub

@Smurf-IV Smurf-IV self-assigned this Jul 16, 2022
@Smurf-IV Smurf-IV added the under investigation This bug/issue is currently under investigation. label Jul 16, 2022
@Smurf-IV
Copy link
Member

Smurf-IV commented Jul 16, 2022

Notes:
Would also fire when the following Sets happen:

  • ItemStyle
  • BackStyle
  • BorderStyle
  • PaletteChanged
  • KryptonTreeView is created!
  • and via the strange OCM_NOTIFY
  • When selected item is deleted (Unknown will set then !)

Now should only fire when:

  • When selected item is deleted (Unknown will set then !)
  • When selected.
  • Sometimes via the strange OCM_Notify

@Smurf-IV
Copy link
Member

Coming to a PR soon....
TreeDontCrash

Smurf-IV added a commit that referenced this issue Jul 16, 2022
…creation finished, or when recreating due to palette changes)

#777
@Smurf-IV Smurf-IV removed their assignment Jul 16, 2022
@Smurf-IV Smurf-IV added this to the Version 7 milestone Jul 16, 2022
@Smurf-IV Smurf-IV added completed This issue has been completed. and removed under investigation This bug/issue is currently under investigation. labels Jul 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working completed This issue has been completed.
Projects
None yet
Development

No branches or pull requests

3 participants