mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
Fix crashes when attempting to import invalid pxo files
This commit is contained in:
parent
b2f511c45b
commit
3f6e1385e0
|
@ -343,7 +343,7 @@ config/icon="res://assets/graphics/icons/icon.png"
|
||||||
config/macos_native_icon="res://assets/graphics/icons/icon.icns"
|
config/macos_native_icon="res://assets/graphics/icons/icon.icns"
|
||||||
config/windows_native_icon="res://assets/graphics/icons/icon.ico"
|
config/windows_native_icon="res://assets/graphics/icons/icon.ico"
|
||||||
config/custom_user_dir_name.X11="pixelorama"
|
config/custom_user_dir_name.X11="pixelorama"
|
||||||
config/Version="v0.11.4-rc1"
|
config/Version="v0.11.4-rc2"
|
||||||
config/ExtensionsAPI_Version=3
|
config/ExtensionsAPI_Version=3
|
||||||
config/Pxo_Version=2
|
config/Pxo_Version=2
|
||||||
|
|
||||||
|
|
|
@ -131,6 +131,16 @@ func open_pxo_file(path: String, untitled_backup: bool = false, replace_empty: b
|
||||||
file.close()
|
file.close()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
var first_line := file.get_line()
|
||||||
|
var dict := JSON.parse(first_line)
|
||||||
|
if dict.error != OK:
|
||||||
|
print("Error, corrupt pxo file")
|
||||||
|
file.close()
|
||||||
|
return
|
||||||
|
if typeof(dict.result) != TYPE_DICTIONARY:
|
||||||
|
print("Error, json parsed result is: %s" % typeof(dict.result))
|
||||||
|
file.close()
|
||||||
|
return
|
||||||
var empty_project: bool = Global.current_project.is_empty() and replace_empty
|
var empty_project: bool = Global.current_project.is_empty() and replace_empty
|
||||||
var new_project: Project
|
var new_project: Project
|
||||||
if empty_project:
|
if empty_project:
|
||||||
|
@ -142,43 +152,31 @@ func open_pxo_file(path: String, untitled_backup: bool = false, replace_empty: b
|
||||||
else:
|
else:
|
||||||
new_project = Project.new([], path.get_file())
|
new_project = Project.new([], path.get_file())
|
||||||
|
|
||||||
var first_line := file.get_line()
|
new_project.deserialize(dict.result)
|
||||||
var dict := JSON.parse(first_line)
|
for frame in new_project.frames:
|
||||||
if dict.error != OK:
|
for cel in frame.cels:
|
||||||
print("Error, corrupt pxo file")
|
cel.load_image_data_from_pxo(file, new_project.size)
|
||||||
file.close()
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
if typeof(dict.result) != TYPE_DICTIONARY:
|
|
||||||
print("Error, json parsed result is: %s" % typeof(dict.result))
|
|
||||||
file.close()
|
|
||||||
return
|
|
||||||
|
|
||||||
new_project.deserialize(dict.result)
|
if dict.result.has("brushes"):
|
||||||
for frame in new_project.frames:
|
for brush in dict.result.brushes:
|
||||||
for cel in frame.cels:
|
var b_width = brush.size_x
|
||||||
cel.load_image_data_from_pxo(file, new_project.size)
|
var b_height = brush.size_y
|
||||||
|
var buffer := file.get_buffer(b_width * b_height * 4)
|
||||||
|
var image := Image.new()
|
||||||
|
image.create_from_data(b_width, b_height, false, Image.FORMAT_RGBA8, buffer)
|
||||||
|
new_project.brushes.append(image)
|
||||||
|
Brushes.add_project_brush(image)
|
||||||
|
|
||||||
if dict.result.has("brushes"):
|
if dict.result.has("tile_mask") and dict.result.has("has_mask"):
|
||||||
for brush in dict.result.brushes:
|
if dict.result.has_mask:
|
||||||
var b_width = brush.size_x
|
var t_width = dict.result.tile_mask.size_x
|
||||||
var b_height = brush.size_y
|
var t_height = dict.result.tile_mask.size_y
|
||||||
var buffer := file.get_buffer(b_width * b_height * 4)
|
var buffer := file.get_buffer(t_width * t_height * 4)
|
||||||
var image := Image.new()
|
var image := Image.new()
|
||||||
image.create_from_data(b_width, b_height, false, Image.FORMAT_RGBA8, buffer)
|
image.create_from_data(t_width, t_height, false, Image.FORMAT_RGBA8, buffer)
|
||||||
new_project.brushes.append(image)
|
new_project.tiles.tile_mask = image
|
||||||
Brushes.add_project_brush(image)
|
else:
|
||||||
|
new_project.tiles.reset_mask()
|
||||||
if dict.result.has("tile_mask") and dict.result.has("has_mask"):
|
|
||||||
if dict.result.has_mask:
|
|
||||||
var t_width = dict.result.tile_mask.size_x
|
|
||||||
var t_height = dict.result.tile_mask.size_y
|
|
||||||
var buffer := file.get_buffer(t_width * t_height * 4)
|
|
||||||
var image := Image.new()
|
|
||||||
image.create_from_data(t_width, t_height, false, Image.FORMAT_RGBA8, buffer)
|
|
||||||
new_project.tiles.tile_mask = image
|
|
||||||
else:
|
|
||||||
new_project.tiles.reset_mask()
|
|
||||||
|
|
||||||
file.close()
|
file.close()
|
||||||
if empty_project:
|
if empty_project:
|
||||||
|
|
Loading…
Reference in a new issue