kayler-renslow / arma-dialog-creator

A dialog/GUI creation tool for Arma 3.
MIT License
76 stars 12 forks source link

Making control class and choosing parrent class for it cause internal error #17

Closed tuntematonjr closed 6 years ago

tuntematonjr commented 7 years ago

Version and Build

1.0.2

Summary

Making control class and choosing parrent class for it cause internal error. https://i.gyazo.com/e4553bef94a816b457a05e59688df797.png Im starting feel bad making these bug reports =D I'm doing stupid things that nobody should do or what =)

Detail

https://pastebin.com/b8dy7shs

kayler-renslow commented 7 years ago

Don't feel bad. You're making the program better. :)

kayler-renslow commented 6 years ago

I figured out how to replicate:

  1. Set a color based property to a Raw value. (I used Static.colorBackground)
  2. Set a parent class that has that property defined to a Color
  3. Inherit the property.
  4. Clear the parent class (extend nothing)
kayler-renslow commented 6 years ago

Order of events:

  1. Override property
  2. Property's value is changed (let this be named Value Update)
  3. Property's value editor is notified of value change.
  4. Error

The source of the problem is that the property's value editor isn't anticipating the PropertyType to change and the editor only edits one PropertyType. For example, the ColorArrayEditor only expects SVColorArray (PropertyType.Color) and results in a ClassCastException because it is casting the ControlProperty's value to SVColorArray, despite it being something else.

Code creating the exception:

// In SVColorArrayEditor.controlPropertyListener.valueUpdated()
    setValue(((SVColorArray) controlProperty.getValue()));

What needs to happen is when a ControlProperty's value is updated but the type is changed, the current editor's value listeners attached to the updated ControlProperty should be disabled prior to the Value Update event. Then the editor won't create an exception. After the value has been set and the inheritance related events have occured, the ControlPropertyEditorContainer should reset the current editor so that it shows the relevant editor and the listeners are re-enabled.

kayler-renslow commented 6 years ago

Fixed in https://github.com/kayler-renslow/arma-dialog-creator/commit/ad772c2837f641a30a3dd144459b18f54822f844.

The fix was creating an event notifying the ControlProperty's listeners that it is inheriting another ControlProperty (named PreemptiveControlPropertyInheritUpdate). This new event takes place before the old inherit update and the value update. Then the editor listens for the PreemptiveControlPropertyInheritUpdate and clears the listeners for the editor. Then when the old inherit update occurs, the editor becomes reset.

kayler-renslow commented 6 years ago

fix applied in version 1.0.3