godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
87.01k stars 19.52k forks source link

Editor crash when opening a project with certain resource #80181

Open KoBeWi opened 11 months ago

KoBeWi commented 11 months ago

Godot version

4.2 dc05278

System information

Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1060 (NVIDIA; 30.0.15.1403) - Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz (8 Threads)

Issue description

I was casually doing something in a project when eventually the editor crashed and then I wasn't able to open the project at all. I removed every file except a single directory, which seems to be cause. It has a few textures and materials. The crash is silent.

Debugger stack:

abort() Line 77 (c:\Users\Tomek\AppData\Local\Programs\Microsoft VS Code\minkernel\crts\ucrt\src\appcrt\startup\abort.cpp:77)
_purecall() Line 29 (d:\a\_work\1\s\src\vctools\crt\vcruntime\src\misc\purevirt.cpp:29)
CommandQueueMT::_flush() Line 374 (c:\godot_source\core\templates\command_queue_mt.h:374)
CommandQueueMT::flush_if_pending() Line 406 (c:\godot_source\core\templates\command_queue_mt.h:406)
RenderingServerDefault::free(RID p_rid) Line 980 (c:\godot_source\servers\rendering\rendering_server_default.h:980)
CompressedTexture2D::~CompressedTexture2D() Line 467 (c:\godot_source\scene\resources\compressed_texture.cpp:467)
CompressedTexture2D::`scalar deleting destructor'(unsigned int) (Nieznane źródło:0)
memdelete<RefCounted>(RefCounted * p_class) Line 112 (c:\godot_source\core\os\memory.h:112)
Variant::_clear_internal() Line 1357 (c:\godot_source\core\variant\variant.cpp:1357)
Variant::clear() Line 304 (c:\godot_source\core\variant\variant.h:304)
Variant::~Variant() Line 784 (c:\godot_source\core\variant\variant.h:784)
Variant::`scalar deleting destructor'(unsigned int) (Nieznane źródło:0)
CowData<Variant>::_unref(void * p_data) Line 214 (c:\godot_source\core\templates\cowdata.h:214)
CowData<Variant>::resize<0>(int p_size) Line 273 (c:\godot_source\core\templates\cowdata.h:273)
Vector<Variant>::resize(int p_size) Line 94 (c:\godot_source\core\templates\vector.h:94)
Vector<Variant>::clear() Line 87 (c:\godot_source\core\templates\vector.h:87)
Array::clear() Line 111 (c:\godot_source\core\variant\array.cpp:111)
RendererRD::MaterialStorage::material_free(RID p_rid) Line 2237 (c:\godot_source\servers\rendering\renderer_rd\storage_rd\material_storage.cpp:2237)
RendererRD::MaterialStorage::free(RID p_rid) Line 1260 (c:\godot_source\servers\rendering\renderer_rd\storage_rd\material_storage.cpp:1260)
RendererRD::Utilities::free(RID p_rid) Line 94 (c:\godot_source\servers\rendering\renderer_rd\storage_rd\utilities.cpp:94)

Steps to reproduce

  1. Open MRP
  2. 💀

Minimal reproduction project

Unfortunately the textures are quite big and I was not able to remove them without fixing the crash. https://ufile.io/gq6ns9o3

mieldepoche commented 11 months ago

I tested with 4.1, and it does crash but with more info (no 4.2 build to test with rn):

``` Godot Engine v4.1.stable.official.970459615 - https://godotengine.org Vulkan API 1.3.224 - Forward+ - Using Vulkan Device #0: NVIDIA - NVIDIA GeForce RTX 3070 WARNING: Invalid pipelines cache header. at: _load_pipeline_cache (drivers/vulkan/rendering_device_vulkan.cpp:9026) --Main Shader-- 1 | shader_type canvas_item; 2 | 3 | 4 | uniform float col_a_min=0.05; 5 | uniform float col_a_max=0.99; 6 | uniform float col_a_pow=0.3; 7 | uniform float rgb_pow=2.0; 8 | uniform bool use_bilinear=true; 9 | 10 | uniform float random_blur =0.5; 11 | uniform float shuffle_tile_border =4.0; 12 | uniform float blur_amount =1.5; 13 | uniform float random_blur_border =4.0; 14 | uniform float random_noise_mul =2.0; 15 | 16 | 17 | uniform float dirt_tile_mul =8.0; 18 | 19 | uniform sampler2D crack_tiled: repeat_enable; 20 | uniform float crack_tile_mul =5.0; 21 | 22 | uniform sampler2D noise_tiled: repeat_enable; 23 | uniform float noise_tile_mul =30.0; 24 | 25 | uniform sampler2D random_noise: repeat_enable; 26 | 27 | 28 | uniform sampler2DArray terrain_texture_mix: repeat_enable,filter_linear_mipmap; E 29-> uniform sampler2D terrain_textures[36]: repeat_enable; 30 | 31 | uniform sampler2D lumen_texture: repeat_enable; 32 | uniform float wall_mul =4.0; 33 | 34 | 35 | 36 | 37 | uniform sampler2D magma: repeat_enable; 38 | uniform vec4 magma_color : source_color= vec4( 2.89, 1.16, 0.0, 1.0); 39 | 40 | uniform sampler2D water_noise; 41 | uniform vec4 water_color : source_color= vec4(0.8,1.2,2.4,1.0); 42 | uniform sampler2D caustics: repeat_enable; 43 | uniform float caustics_mul =15.0; 44 | 45 | uniform vec4 lumen_color; 46 | uniform vec4 lumen_glitter_color; 47 | uniform float lumen_mul; 48 | uniform float lumen_glitter_power; 49 | uniform sampler2D lava_data: hint_default_black; 50 | uniform int lava_data_count; 51 | 52 | const float black_fade_array[33] = {4.0, 2.0, 6.0, 1.0, 1.0, 9.0, 7.0, 1.0, 1.0, 1.0, 53 | 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 8.0, 54 | 1.0, 8.0, 8.0, 8.0, 1.0, 10.0, 8.0, 12.0, 1.0, 1.0, 55 | 9.0,1.0,0.0}; 56 | 57 | uniform sampler2D SCREEN_TEXTURE: hint_screen_texture, filter_linear_mipmap; 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | float when_eq(float x, float y) { 70 | return 1.0 - abs(sign(x - y)); 71 | } 72 | 73 | float when_neq(float x, float y) { 74 | return abs(sign(x - y)); 75 | } 76 | 77 | 78 | 79 | 80 | vec4 get_shuffled_color(vec2 UV_in, sampler2D map_texture, vec2 random_blur_scaled, vec2 UV_in_scaled, vec2 tex_size) 81 | { 82 | 83 | vec4 col_res=texelFetch(map_texture, ivec2((UV_in+17.0* random_blur_scaled*(texture(random_noise,UV_in_scaled*shuffle_tile_border).rg-vec2(0.5,0.5)))*tex_size),0); 84 | 85 | return col_res; 86 | } 87 | 88 | vec4 getWaterColor(vec2 UV_in) 89 | { 90 | UV_in*=0.8; 91 | vec4 outCOLOR=vec4(0.5)* water_color; 92 | 93 | 94 | float textureOffset = TIME / 90.0; 95 | vec2 waveOne = UV_in*3.0 + vec2(textureOffset, textureOffset); 96 | 97 | vec4 sampleOne = texture(water_noise, waveOne)*0.01 ; 98 | 99 | textureOffset += TIME / 140.0; 100 | vec2 waveTwo = UV_in*5.0 - vec2(textureOffset, -textureOffset); 101 | vec4 sampleTwo = texture(water_noise, waveTwo)*0.01; 102 | 103 | vec2 calc_uv= sampleOne.xy + sampleTwo.xy; 104 | 105 | 106 | outCOLOR.rgb+=vec3(pow(textureLod(caustics,caustics_mul*UV_in +calc_uv-TIME*0.02,2.54).r,8.0)*0.5); 107 | float textureOffset_spec = TIME / 40.0; 108 | vec2 waveOne_spec = UV_in*30.0 + vec2(textureOffset_spec, textureOffset_spec); 109 | vec4 sampleOne_spec = texture(water_noise, waveOne_spec) ; 110 | 111 | 112 | textureOffset_spec = TIME / 44.0; 113 | vec2 waveTwo_spec = UV_in*20.0 - vec2(textureOffset_spec, textureOffset_spec); 114 | vec4 sampleTwo_spec = texture(water_noise, waveTwo_spec); 115 | 116 | 117 | 118 | 119 | vec4 col=(sampleTwo_spec+sampleOne_spec)*0.5; 120 | 121 | 122 | 123 | 124 | 125 | if(col.b>0.95) 126 | outCOLOR+= vec4(0.5,0.5,1.0,0.0)*(col.b-0.95)*30.0; 127 | 128 | if(col.g>0.6) 129 | outCOLOR+= vec4(1.0,1.0,1.0,0.0)*(col.g-0.6)*1.5; 130 | 131 | outCOLOR=clamp(outCOLOR,vec4(0.0),vec4(1.4)); 132 | 133 | 134 | 135 | return outCOLOR; 136 | } 137 | 138 | vec4 getLavaColor(sampler2D map_texture,vec2 UV_in, vec2 SCREEN_UV_in, float tim) 139 | { 140 | UV_in*=0.4; 141 | vec4 outCOLOR=vec4(0.0); 142 | vec2 t=vec2(tim*0.005); 143 | vec3 field = textureLod(magma,UV_in*50.0*0.5+t*0.45,1.0).rgb + vec3(230,127,25)/255.; 144 | float lum = textureLod(magma,UV_in*50.0*0.5-t*3.5+(field.rg-field.gb)/2.,1.0).g*1.0; 145 | outCOLOR = vec4(lum*magma_color.rgb,0.5)*2.8; 146 | return outCOLOR; 147 | } 148 | 149 | 150 | 151 | mat2 makem2(in float theta){float c = cos(theta);float s = sin(theta);return mat2(vec2(c,-s),vec2(s,c));} 152 | float noise( in vec2 x ){return texture(random_noise, x*.01).x;} 153 | 154 | vec2 gradn(vec2 p) 155 | { 156 | float ep = 0.9; 157 | float gradx = noise(vec2(p.x+ep,p.y))-noise(vec2(p.x-ep,p.y)); 158 | float grady = noise(vec2(p.x,p.y+ep))-noise(vec2(p.x,p.y-ep)); 159 | return vec2(gradx,grady); 160 | } 161 | 162 | float flow(in vec2 p,float time,float lava_dist,vec2 vec_from_source) 163 | { 164 | float z=20.; 165 | float rz = 0.01; 166 | vec2 bp = p; 167 | for (float i= 1.;i < 4.;i++ ) 168 | { 169 | float sin_dist = sin((length(vec_from_source) -time*110.01)*0.1 )*10.110; 170 | vec2 shiftedUV= ( normalize(vec_from_source)*(sin_dist+12.0) ); 171 | 172 | 173 | 174 | p += shiftedUV*0.012*lava_dist; 175 | 176 | 177 | 178 | 179 | 180 | bp += shiftedUV*0.07*1.0*lava_dist; 181 | 182 | 183 | vec2 gr = gradn(i*p*0.5+time*1.00); 184 | 185 | 186 | gr*=makem2(time*6.-(0.05*p.x+0.03*p.y)*40.); 187 | 188 | 189 | p += gr*.15; 190 | 191 | 192 | rz+= (sin(noise(p)*7.)*0.5+0.6)/(z*(lava_dist+0.1)); 193 | 194 | 195 | 196 | p = mix(bp,p,1.07); 197 | 198 | 199 | z *= 1.4; 200 | 201 | p *= 5.; 202 | bp *= 5.01; 203 | } 204 | return rz; 205 | } 206 | 207 | 208 | 209 | 210 | vec4 getLava2Color(vec2 UV_in, float tim, vec4 lava_posx_posy_radius) 211 | { 212 | UV_in=vec2(UV_in.x*1.0,UV_in.y*2.0); 213 | vec2 lava_source=vec2(lava_posx_posy_radius.r,lava_posx_posy_radius.g); 214 | float lava_radius=lava_posx_posy_radius.b; 215 | float lava_dist=clamp((lava_radius-distance(UV_in*1000.0,lava_source))/lava_radius,0.05,1.0); 216 | 217 | 218 | float rz = flow(UV_in*180.4,tim*0.1,lava_dist,UV_in*20.0-lava_source)*0.3; 219 | 220 | vec3 col = vec3(.2,0.07,0.01)/rz; 221 | col=pow(col,vec3(1.3)); 222 | 223 | return vec4(col.rgb*0.25,1.0); 224 | } 225 | 226 | vec3 addCracks(vec2 UV_in_scaled, vec4 real_col, vec4 col) 227 | { 228 | vec4 crack=texture(crack_tiled, vec2(UV_in_scaled*crack_tile_mul)); 229 | float healthy=clamp(1.0-(pow(col.r, 2.0)),0.0,1.0); 230 | return (1.0-crack.rgb)*healthy+vec3(0.8*clamp(healthy-0.4,0.0,0.1)); 231 | } 232 | 233 | vec4 get_pixel_color(vec4 real_col,vec4 col,vec2 UV_in_scaled) 234 | { 235 | 236 | float resource_type=real_col.g*255.0; 237 | 238 | vec4 outCOLOR=vec4(0.0); 239 | if(abs(resource_type-27.0)<0.1) 240 | { 241 | outCOLOR=texture(lumen_texture,vec2(UV_in_scaled*dirt_tile_mul*wall_mul))*lumen_color; 242 | 243 | outCOLOR.rgb=outCOLOR.rgb+0.8*addCracks(UV_in_scaled,real_col,col); 244 | 245 | outCOLOR.rgb +=(1.0-(texture(crack_tiled, UV_in_scaled).r)) * 0.55; 246 | 247 | 248 | float result = 0.0; 249 | result += texture(random_noise, UV_in_scaled * 2.1045 + vec2(TIME*-0.005)).r; 250 | result *= texture(random_noise, UV_in_scaled * 2.104 + vec2(TIME*+0.005)).g; 251 | result = pow(result, lumen_glitter_power); 252 | 253 | outCOLOR = (outCOLOR+ lumen_mul*lumen_glitter_color*result); 254 | 255 | } 256 | else if(abs(resource_type-26.0)<0.1) 257 | { 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | } 274 | else if(abs(resource_type-29.0)<0.1) 275 | { 276 | outCOLOR= getWaterColor(UV_in_scaled); 277 | } 278 | else if(abs(resource_type-30.0)<0.1) 279 | { 280 | int lava_source_id=clamp(int(real_col.b*255.0),0,lava_data_count-1); 281 | vec4 lava_posx_posy_radius = texelFetch(lava_data, ivec2(lava_source_id,0), 0); 282 | outCOLOR= getLava2Color(UV_in_scaled*vec2(1.0,1.0),TIME,lava_posx_posy_radius); 283 | } 284 | else 285 | { 286 | 287 | 288 | outCOLOR=texture(terrain_textures[int(resource_type)],vec2((UV_in_scaled)*dirt_tile_mul) *vec2(1.0,1.5)); 289 | 290 | outCOLOR.rgb=max(vec3(0.0),(outCOLOR.rgb-addCracks(UV_in_scaled,real_col,col))); 291 | } 292 | return outCOLOR; 293 | } 294 | 295 | 296 | 297 | vec4 get_pixel_color_izo(vec4 real_col,vec4 col,vec2 UV_in_scaled) 298 | { 299 | return get_pixel_color(real_col,col,UV_in_scaled)*2.0; 300 | } 301 | 302 | 303 | vec4 getMapColorPreh2(sampler2D map_texture,vec2 UV_in, sampler2D SCREEN_TEXTURE_in, vec2 SCREEN_UV_in, float tim) 304 | { 305 | 306 | vec2 tex_size=vec2(textureSize(map_texture,0)); 307 | vec2 inv_size=1.0/tex_size; 308 | 309 | vec4 real_col=texelFetch(map_texture, ivec2(UV_in*tex_size),0); 310 | 311 | vec2 UV_in_scaled=UV_in*tex_size*0.001; 312 | 313 | 314 | 315 | vec2 random_blur_scaled=random_blur*inv_size; 316 | vec2 random_blur_border_scaled=random_blur_border*inv_size; 317 | 318 | 319 | 320 | vec4 col=textureLod(map_texture, UV_in+ random_blur_border_scaled* (texture(random_noise,UV_in_scaled*random_noise_mul).rg-vec2(0.55)),blur_amount); 321 | 322 | 323 | 324 | 325 | vec4 col_res=get_shuffled_color(UV_in,map_texture,random_blur_scaled,UV_in_scaled,tex_size); 326 | 327 | 328 | vec4 real_neighbour_cols[9]; 329 | vec4 calculated_neighbour_cols[9]; 330 | vec4 avg_col=vec4(0.0); 331 | vec4 avg_pixel_color=vec4(0.0); 332 | for(int i =0; i<=2;++i) 333 | for(int j =0; j<=2;++j) 334 | { 335 | real_neighbour_cols[i*3+j]=texelFetch(map_texture, ivec2((UV_in+0.5*inv_size*float(use_bilinear))*tex_size)+ivec2(i-1,j-1),0); 336 | calculated_neighbour_cols[i*3+j]=get_pixel_color(real_neighbour_cols[i*3+j],col,UV_in_scaled); 337 | avg_pixel_color+=calculated_neighbour_cols[i*3+j]; 338 | avg_col+=real_neighbour_cols[i*3+j]; 339 | } 340 | 341 | avg_pixel_color=avg_pixel_color/9.0; 342 | avg_col=avg_col/9.0; 343 | avg_pixel_color.a=col.a; 344 | 345 | 346 | 347 | 348 | 349 | vec4 outCOLOR=avg_pixel_color; 350 | outCOLOR=calculated_neighbour_cols[4]; 351 | float resource_type=(real_col.g*255.0); 352 | 353 | if(use_bilinear) 354 | { 355 | vec2 uv = UV_in+inv_size*0.5; 356 | vec2 blend = fract(uv * tex_size); 357 | 358 | vec4 col_x1 = calculated_neighbour_cols[0]; 359 | vec4 col_x2 =calculated_neighbour_cols[3]; 360 | vec4 col_y1 = calculated_neighbour_cols[1]; 361 | vec4 col_y2 =calculated_neighbour_cols[4]; 362 | 363 | vec4 col_x = mix(col_x1, col_x2, blend.x); 364 | vec4 col_y = mix(col_y1, col_y2, blend.x); 365 | vec4 bilinear_color = mix(col_x, col_y, blend.y); 366 | outCOLOR=bilinear_color; 367 | } 368 | 369 | vec4 col_res1=get_shuffled_color(UV_in+vec2(0,1)*inv_size,map_texture,random_blur_scaled,UV_in_scaled,tex_size); 370 | vec4 col_res2=get_shuffled_color(UV_in+vec2(0,2)*inv_size,map_texture,random_blur_scaled,UV_in_scaled,tex_size); 371 | vec4 col_res3=get_shuffled_color(UV_in+vec2(0,3)*inv_size,map_texture,random_blur_scaled,UV_in_scaled,tex_size); 372 | 373 | 374 | 375 | if (col_res1.a<1.0 || col_res2.a<1.0 || col_res3.a<1.0) 376 | outCOLOR=get_pixel_color(col_res,col,UV_in_scaled)*0.5; 377 | else 378 | outCOLOR=get_pixel_color(col_res,col,UV_in_scaled); 379 | 380 | 381 | 382 | 383 | 384 | 385 | if(noise_tile_mul>0.0) 386 | { 387 | vec4 noise=texture(noise_tiled, UV_in_scaled*noise_tile_mul); 388 | outCOLOR.rgb*=0.4+noise.rgb; 389 | } 390 | 391 | 392 | 393 | 394 | 395 | outCOLOR.a=max(real_col.a,col.a); 396 | if ( col.acol_a_min) 397 | { 398 | 399 | outCOLOR.a=pow(col.a,col_a_pow); 400 | outCOLOR.rgb*=pow(col.a,rgb_pow); 401 | } 402 | 403 | 404 | 405 | return outCOLOR; 406 | } 407 | 408 | varying flat vec4 modulate; 409 | void vertex() { 410 | modulate = COLOR; 411 | } 412 | void fragment() 413 | { 414 | COLOR=getMapColorPreh2(TEXTURE,UV,TEXTURE,SCREEN_UV,TIME)*modulate; 415 | 416 | } SHADER ERROR: This hint is not supported for uniform arrays. at: (null) (:29) ERROR: Shader compilation failed. at: set_code (servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp:2059) ERROR: Unable to open file: res://.godot/imported/Terrain.png-22afe6d5106a492da8524c204094f0fe.ctexarray. at: _load_data (scene/resources/texture.cpp:3097) ERROR: Condition "!tex" is true. at: texture_set_size_override (servers/rendering/renderer_rd/storage_rd/texture_storage.cpp:1377) ERROR: Condition "!tex" is true. at: texture_set_path (servers/rendering/renderer_rd/storage_rd/texture_storage.cpp:1386) ERROR: Condition "!tex" is true. at: texture_set_detect_3d_callback (servers/rendering/renderer_rd/storage_rd/texture_storage.cpp:1400) ERROR: Condition "!tex" is true. at: texture_set_detect_roughness_callback (servers/rendering/renderer_rd/storage_rd/texture_storage.cpp:1416) ERROR: Condition "!tex" is true. at: texture_set_detect_normal_callback (servers/rendering/renderer_rd/storage_rd/texture_storage.cpp:1408) ERROR: Condition "!tex" is true. at: texture_set_path (servers/rendering/renderer_rd/storage_rd/texture_storage.cpp:1386) ERROR: Initializing already initialized RID at: get_or_null (./core/templates/rid_owner.h:182) ERROR: Condition "!mem" is true. at: initialize_rid (./core/templates/rid_owner.h:214) ERROR: Condition "!shader" is true. at: material_set_shader (servers/rendering/renderer_rd/storage_rd/material_storage.cpp:2269) ERROR: Condition "!_fp" is true. at: _ref (core/variant/array.cpp:55) free(): corrupted unsorted chunks Aborted (core dumped) ```

as pointed out, removing the repeat_enable thing fixes the editor crash on my end (so in 4.1 stable).

KoBeWi commented 11 months ago

@mieldepoche repeat_enable for sampler arrays is not supported in 4.1, hence the error. Removing it does not fix the crash for me.

EDIT: Although removing texture arrays from stored ShaderMaterial parameters does fix the crash. Which is weird, because it was working perfectly, until it stopped for no reason.

KoBeWi commented 11 months ago

Ok found what causes it 😬😬😬 The crash happens at startup in a destructor. Sus, isn't it? Well, that's because the material is loaded and destroyed. It happens on launch and inside a thread. The culprit is resource preview generator. I "fixed" the crash by placing the material in a gdignored folder 🤦‍♂️

leopeltola commented 2 weeks ago

I'm not sure if this is the same bug but I encountered something similar. changing a loaded scene from var -> const causes core/variant/array.cpp:55 - Parameter "_fp" is null. and editor crashes. However, this is fixed when I remove my assets folder (images and sound files).

https://github.com/godotengine/godot/assets/49021946/e5560164-e656-4f7e-8d03-e0fdc5d4e39f