Skip to content

Commit f8e8724

Browse files
committed
Texture handling fixes
1 parent cf55c60 commit f8e8724

File tree

5 files changed

+56
-46
lines changed

5 files changed

+56
-46
lines changed

base/sources/iron.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,9 @@ gpu_texture_t *gpu_create_texture_from_bytes(buffer_t *data, i32 width, i32 heig
11171117
}
11181118

11191119
gpu_texture_t *gpu_create_texture_from_encoded_bytes(buffer_t *data, string_t *format) {
1120+
if (data == NULL || data->length == 0) {
1121+
return NULL;
1122+
}
11201123
gpu_texture_t *texture = (gpu_texture_t *)malloc(sizeof(gpu_texture_t));
11211124
texture->buffer = NULL;
11221125
unsigned char *texture_data;

paint/sources/export_arm.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,12 @@ function export_arm_run_project() {
193193
function export_arm_export_node(n: ui_node_t, assets: asset_t[] = null) {
194194
if (n.type == "TEX_IMAGE") {
195195
let index: i32 = n.buttons[0].default_value[0];
196-
n.buttons[0].data = u8_array_create_from_string(base_enum_texts(n.type)[index]);
197-
196+
if (index > 9000) { // 9999 - Texture deleted
197+
n.buttons[0].data = u8_array_create_from_string("");
198+
}
199+
else {
200+
n.buttons[0].data = u8_array_create_from_string(base_enum_texts(n.type)[index]);
201+
}
198202
if (assets != null) {
199203
let asset: asset_t = project_assets[index];
200204
if (array_index_of(assets, asset) == -1) {

paint/sources/tab_textures.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -222,28 +222,28 @@ function tab_textures_draw(htab: ui_handle_t) {
222222
}
223223
}
224224

225-
function tab_textures_update_texture_pointers(nodes: ui_node_t[], i: i32) {
225+
function tab_textures_update_texture_pointers(nodes: ui_node_t[], index: i32) {
226226
for (let i: i32 = 0; i < nodes.length; ++i) {
227227
let n: ui_node_t = nodes[i];
228228
if (n.type == "TEX_IMAGE") {
229-
if (n.buttons[0].default_value[0] == i) {
229+
if (n.buttons[0].default_value[0] == index) {
230230
n.buttons[0].default_value[0] = 9999; // Texture deleted, use pink now
231231
}
232-
else if (n.buttons[0].default_value[0] > i) {
232+
else if (n.buttons[0].default_value[0] > index) {
233233
n.buttons[0].default_value[0]--; // Offset by deleted texture
234234
}
235235
}
236236
}
237237
}
238238

239239
function tab_textures_delete_texture(asset: asset_t) {
240-
let i: i32 = array_index_of(project_assets, asset);
240+
let index: i32 = array_index_of(project_assets, asset);
241241
if (project_assets.length > 1) {
242-
context_raw.texture = project_assets[i == project_assets.length - 1 ? i - 1 : i + 1];
242+
context_raw.texture = project_assets[index == project_assets.length - 1 ? index - 1 : index + 1];
243243
}
244244
ui_base_hwnds[tab_area_t.STATUS].redraws = 2;
245245

246-
if (context_raw.tool == tool_type_t.COLORID && i == context_raw.colorid_handle.i) {
246+
if (context_raw.tool == tool_type_t.COLORID && index == context_raw.colorid_handle.i) {
247247
ui_header_handle.redraws = 2;
248248
context_raw.ddirty = 2;
249249
context_raw.colorid_picked = false;
@@ -266,22 +266,21 @@ function tab_textures_delete_texture(asset: asset_t) {
266266

267267
data_delete_image(asset.file);
268268
map_delete(project_asset_map, asset.id);
269-
array_splice(project_assets, i, 1);
270-
array_splice(project_asset_names, i, 1);
269+
array_splice(project_assets, index, 1);
270+
array_splice(project_asset_names, index, 1);
271271
sys_notify_on_next_frame(function() {
272272
make_material_parse_paint_material();
273-
274273
util_render_make_material_preview();
275274
ui_base_hwnds[tab_area_t.SIDEBAR1].redraws = 2;
276275
});
277276

278277
for (let i: i32 = 0; i < project_materials.length; ++i) {
279278
let m: slot_material_t = project_materials[i];
280-
tab_textures_update_texture_pointers(m.canvas.nodes, i);
279+
tab_textures_update_texture_pointers(m.canvas.nodes, index);
281280
}
282281

283282
for (let i: i32 = 0; i < project_brushes.length; ++i) {
284283
let b: slot_brush_t = project_brushes[i];
285-
tab_textures_update_texture_pointers(b.canvas.nodes, i);
284+
tab_textures_update_texture_pointers(b.canvas.nodes, index);
286285
}
287286
}

paint/sources/ui_files.ts

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -201,30 +201,32 @@ function ui_files_file_browser(handle: ui_handle_t, drag_files: bool = false, se
201201
file_cache_cloud(handle.text + path_sep + icon_file, function(abs: string) {
202202
if (abs != null) {
203203
let image: gpu_texture_t = data_get_image(abs);
204-
/// if arm_windows
205-
abs = string_replace_all(abs, "\\", "/");
206-
/// end
207-
let icon_file: string = substring(abs, string_last_index_of(abs, "/") + 1, abs.length);
208-
let f: string = map_get(ui_files_icon_file_map, icon_file);
209-
let data: draw_cloud_icon_data_t = make_draw_cloud_icon_data(f, image);
210-
211-
sys_notify_on_next_frame(function(data: draw_cloud_icon_data_t) {
212-
let icon: gpu_texture_t = gpu_create_render_target(data.image.width, data.image.height);
213-
if (ends_with(data.f, ".arm")) { // Used for material sphere alpha cutout
214-
draw_begin(icon);
215-
draw_image(project_materials[0].image, 0, 0);
216-
}
217-
else {
218-
draw_begin(icon, true, 0xffffffff);
219-
}
220-
draw_set_pipeline(pipes_copy_rgb);
221-
draw_image(data.image, 0, 0);
222-
draw_set_pipeline(null);
223-
draw_end();
224-
225-
map_set(ui_files_icon_map, _ui_files_file_browser_handle.text + path_sep + data.f, icon);
226-
ui_base_hwnds[tab_area_t.STATUS].redraws = 3;
227-
}, data);
204+
if (image != null) {
205+
/// if arm_windows
206+
abs = string_replace_all(abs, "\\", "/");
207+
/// end
208+
let icon_file: string = substring(abs, string_last_index_of(abs, "/") + 1, abs.length);
209+
let f: string = map_get(ui_files_icon_file_map, icon_file);
210+
let data: draw_cloud_icon_data_t = make_draw_cloud_icon_data(f, image);
211+
212+
sys_notify_on_next_frame(function(data: draw_cloud_icon_data_t) {
213+
let icon: gpu_texture_t = gpu_create_render_target(data.image.width, data.image.height);
214+
if (ends_with(data.f, ".arm")) { // Used for material sphere alpha cutout
215+
draw_begin(icon);
216+
draw_image(project_materials[0].image, 0, 0);
217+
}
218+
else {
219+
draw_begin(icon, true, 0xffffffff);
220+
}
221+
draw_set_pipeline(pipes_copy_rgb);
222+
draw_image(data.image, 0, 0);
223+
draw_set_pipeline(null);
224+
draw_end();
225+
226+
map_set(ui_files_icon_map, _ui_files_file_browser_handle.text + path_sep + data.f, icon);
227+
ui_base_hwnds[tab_area_t.STATUS].redraws = 3;
228+
}, data);
229+
}
228230
}
229231
else {
230232
ui_files_offline = true;

paint/sources/ui_nodes.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,16 +1150,18 @@ function ui_nodes_get_node_preview_image(n: ui_node_t): gpu_texture_t {
11501150
}
11511151
else if (n.type == "TEX_IMAGE" && parser_material_get_input_link(n.inputs[0]) == null) {
11521152
let i: i32 = n.buttons[0].default_value[0];
1153-
let filepath: string = parser_material_enum_data(base_enum_texts(n.type)[i]);
1154-
let asset_index: i32 = -1;
1155-
for (let i: i32 = 0; i < project_assets.length; ++i) {
1156-
if (project_assets[i].file == filepath) {
1157-
asset_index = i;
1158-
break;
1153+
if (i <= 9000) { // 9999 - Texture deleted
1154+
let filepath: string = parser_material_enum_data(base_enum_texts(n.type)[i]);
1155+
let asset_index: i32 = -1;
1156+
for (let i: i32 = 0; i < project_assets.length; ++i) {
1157+
if (project_assets[i].file == filepath) {
1158+
asset_index = i;
1159+
break;
1160+
}
1161+
}
1162+
if (asset_index > -1) {
1163+
img = project_get_image(project_assets[asset_index]);
11591164
}
1160-
}
1161-
if (asset_index > -1) {
1162-
img = project_get_image(project_assets[asset_index]);
11631165
}
11641166
}
11651167
else if (starts_with(n.type, "NEURAL_") && n.type != "NEURAL_IMAGE_TO_PBR") {

0 commit comments

Comments
 (0)