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

Avoid crashing on first installation #182

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions project/addons/terrain_3d/editor/components/toolbar.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ extends VBoxContainer

signal tool_changed(p_tool: Terrain3DEditor.Tool, p_operation: Terrain3DEditor.Operation)

const ICON_REGION_ADD: Texture2D = preload("res://addons/terrain_3d/icons/icon_map_add.svg")
const ICON_REGION_REMOVE: Texture2D = preload("res://addons/terrain_3d/icons/icon_map_remove.svg")
const ICON_HEIGHT_ADD: Texture2D = preload("res://addons/terrain_3d/icons/icon_height_add.svg")
const ICON_HEIGHT_SUB: Texture2D = preload("res://addons/terrain_3d/icons/icon_height_sub.svg")
const ICON_HEIGHT_MUL: Texture2D = preload("res://addons/terrain_3d/icons/icon_height_mul.svg")
const ICON_HEIGHT_DIV: Texture2D = preload("res://addons/terrain_3d/icons/icon_height_div.svg")
const ICON_HEIGHT_FLAT: Texture2D = preload("res://addons/terrain_3d/icons/icon_height_flat.svg")
const ICON_HEIGHT_SMOOTH: Texture2D = preload("res://addons/terrain_3d/icons/icon_height_smooth.svg")
const ICON_PAINT_TEXTURE: Texture2D = preload("res://addons/terrain_3d/icons/icon_brush.svg")
const ICON_SPRAY_TEXTURE: Texture2D = preload("res://addons/terrain_3d/icons/icon_spray.svg")
const ICON_PAINT_COLOR: Texture2D = preload("res://addons/terrain_3d/icons/icon_color.svg")
const ICON_PAINT_ROUGHNESS: Texture2D = preload("res://addons/terrain_3d/icons/icon_roughness.svg")
const ICON_REGION_ADD: String = "res://addons/terrain_3d/icons/icon_map_add.svg"
const ICON_REGION_REMOVE: String = "res://addons/terrain_3d/icons/icon_map_remove.svg"
const ICON_HEIGHT_ADD: String = "res://addons/terrain_3d/icons/icon_height_add.svg"
const ICON_HEIGHT_SUB: String = "res://addons/terrain_3d/icons/icon_height_sub.svg"
const ICON_HEIGHT_MUL: String = "res://addons/terrain_3d/icons/icon_height_mul.svg"
const ICON_HEIGHT_DIV: String = "res://addons/terrain_3d/icons/icon_height_div.svg"
const ICON_HEIGHT_FLAT: String = "res://addons/terrain_3d/icons/icon_height_flat.svg"
const ICON_HEIGHT_SMOOTH: String = "res://addons/terrain_3d/icons/icon_height_smooth.svg"
const ICON_PAINT_TEXTURE: String = "res://addons/terrain_3d/icons/icon_brush.svg"
const ICON_SPRAY_TEXTURE: String = "res://addons/terrain_3d/icons/icon_spray.svg"
const ICON_PAINT_COLOR: String = "res://addons/terrain_3d/icons/icon_color.svg"
const ICON_PAINT_ROUGHNESS: String = "res://addons/terrain_3d/icons/icon_roughness.svg"

var tool_group: ButtonGroup = ButtonGroup.new()

Expand All @@ -26,21 +26,21 @@ func _init() -> void:
func _ready() -> void:
tool_group.connect("pressed", _on_tool_selected)

add_tool_button(Terrain3DEditor.REGION, Terrain3DEditor.ADD, "Add Region", ICON_REGION_ADD, tool_group)
add_tool_button(Terrain3DEditor.REGION, Terrain3DEditor.SUBTRACT, "Delete Region", ICON_REGION_REMOVE, tool_group)
add_tool_button(Terrain3DEditor.REGION, Terrain3DEditor.ADD, "Add Region", load(ICON_REGION_ADD), tool_group)
add_tool_button(Terrain3DEditor.REGION, Terrain3DEditor.SUBTRACT, "Delete Region", load(ICON_REGION_REMOVE), tool_group)
add_child(HSeparator.new())
add_tool_button(Terrain3DEditor.HEIGHT, Terrain3DEditor.ADD, "Raise", ICON_HEIGHT_ADD, tool_group)
add_tool_button(Terrain3DEditor.HEIGHT, Terrain3DEditor.SUBTRACT, "Lower", ICON_HEIGHT_SUB, tool_group)
add_tool_button(Terrain3DEditor.HEIGHT, Terrain3DEditor.MULTIPLY, "Expand (Away from 0)", ICON_HEIGHT_MUL, tool_group)
add_tool_button(Terrain3DEditor.HEIGHT, Terrain3DEditor.DIVIDE, "Reduce (Towards 0)", ICON_HEIGHT_DIV, tool_group)
add_tool_button(Terrain3DEditor.HEIGHT, Terrain3DEditor.REPLACE, "Flatten", ICON_HEIGHT_FLAT, tool_group)
add_tool_button(Terrain3DEditor.HEIGHT, Terrain3DEditor.AVERAGE, "Smooth", ICON_HEIGHT_SMOOTH, tool_group)
add_tool_button(Terrain3DEditor.HEIGHT, Terrain3DEditor.ADD, "Raise", load(ICON_HEIGHT_ADD), tool_group)
add_tool_button(Terrain3DEditor.HEIGHT, Terrain3DEditor.SUBTRACT, "Lower", load(ICON_HEIGHT_SUB), tool_group)
add_tool_button(Terrain3DEditor.HEIGHT, Terrain3DEditor.MULTIPLY, "Expand (Away from 0)", load(ICON_HEIGHT_MUL), tool_group)
add_tool_button(Terrain3DEditor.HEIGHT, Terrain3DEditor.DIVIDE, "Reduce (Towards 0)", load(ICON_HEIGHT_DIV), tool_group)
add_tool_button(Terrain3DEditor.HEIGHT, Terrain3DEditor.REPLACE, "Flatten", load(ICON_HEIGHT_FLAT), tool_group)
add_tool_button(Terrain3DEditor.HEIGHT, Terrain3DEditor.AVERAGE, "Smooth", load(ICON_HEIGHT_SMOOTH), tool_group)
add_child(HSeparator.new())
add_tool_button(Terrain3DEditor.TEXTURE, Terrain3DEditor.REPLACE, "Paint Texture", ICON_PAINT_TEXTURE, tool_group)
add_tool_button(Terrain3DEditor.TEXTURE, Terrain3DEditor.ADD, "Spray Texture", ICON_SPRAY_TEXTURE, tool_group)
add_tool_button(Terrain3DEditor.TEXTURE, Terrain3DEditor.REPLACE, "Paint Texture", load(ICON_PAINT_TEXTURE), tool_group)
add_tool_button(Terrain3DEditor.TEXTURE, Terrain3DEditor.ADD, "Spray Texture", load(ICON_SPRAY_TEXTURE), tool_group)
add_child(HSeparator.new())
add_tool_button(Terrain3DEditor.COLOR, Terrain3DEditor.REPLACE, "Paint Color", ICON_PAINT_COLOR, tool_group)
add_tool_button(Terrain3DEditor.ROUGHNESS, Terrain3DEditor.REPLACE, "Paint Roughness", ICON_PAINT_ROUGHNESS, tool_group)
add_tool_button(Terrain3DEditor.COLOR, Terrain3DEditor.REPLACE, "Paint Color", load(ICON_PAINT_COLOR), tool_group)
add_tool_button(Terrain3DEditor.ROUGHNESS, Terrain3DEditor.REPLACE, "Paint Roughness", load(ICON_PAINT_ROUGHNESS), tool_group)

var buttons: Array[BaseButton] = tool_group.get_buttons()
buttons[0].set_pressed(true)
Expand Down
8 changes: 8 additions & 0 deletions project/addons/terrain_3d/editor/editor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ var region_gizmo: RegionGizmo
var current_region_position: Vector2
var mouse_global_position: Vector3 = Vector3.ZERO

var first_run: bool false


func _enter_tree() -> void:
if ClassDB.class_exists("Terrain3DEditor"):
first_run = true
OS.alert("Restart the editor to use the Terrain3D plugin")
return
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to run every time, not the first time after installing the plugin only. Alright, let's drop this commit and just go with the first commit which partially resolves the issue by removing the errors. Later someone will look into initiating a restart before the crash via C++. Thanks.

editor = Terrain3DEditor.new()
ui = UI.new()
ui.plugin = self
Expand All @@ -42,6 +48,8 @@ func _enter_tree() -> void:


func _exit_tree() -> void:
if first_run:
return
remove_control_from_container(surface_list_container, surface_list)
surface_list.queue_free()
ui.queue_free()
Expand Down