Scirra / Construct-bugs

Public bug report submissions for Construct 3 and Construct Animate. Please read the guidelines then click the 'Issues' tab to get started.
https://www.construct.net
108 stars 83 forks source link

Array conditions failing tautological comparisons after a string's value is compared to the array's current value. #8091

Closed Tafubitto closed 2 months ago

Tafubitto commented 3 months ago

Problem description

In an Array object's "For each XY element" loop, in one strange case after the current value is compared to a string variable, the conditions "Compare at XY" and "Compare current value" break, to the point that comparing a value to itself will fail.

Attach a .c3p

Array For Each Bug.zip

Steps to reproduce

  1. Open the project preview, it will automatically print out tests for the issue in the devtools console.

Observed result

When checking for 4 in a row diagonally (seen in the first group logged at (curX: 0, curY:0)), the four in a row exists, but as a side effect, 3 array events become unreachable. The conditions for these are:

  1. Current value = Self.CurValue
  2. Value at (Self.CurX, Self.CurY) = Self.CurValue
  3. Value at (Self.CurX, Self.CurY) = Self.At(Self.CurX, Self.CurY)

But the event for the System condition, Array.CurValue = Array.CurValue, IS reachable.

Expected result

The three conditions listed above are tautological, so they shouldn't be making the event unreachable.

More details

I suspect the issue has something to do with event 5, which checks if a local string variable is empty or equal to the array's current value. Disabling those conditions makes the tests pass just fine. But in this code, the string isn't being modified yet it still causes the issue. In my project where the local string is being set, it still breaks.

I could use the System condition style since that works as expected, but this doesn't seem like correct behavior for the Array object.

Affected browsers/platforms: Edge and Firefox, likely all browsers

First affected release: Unsure

System details

View details Platform information Product: Construct 3 r397 (stable) Browser: Edge 126.0.2592.68 Browser engine: Chromium Context: browser Operating system: Windows 11 Device type: desktop Device pixel ratio: 1 Logical CPU cores: 6 Approx. device memory: 8 GB User agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0 Language setting: en-US Local storage Storage quota (approx): 285 gb Storage usage (approx): 267 mb (0.1%) Persistant storage: No Browser support notes This list contains missing features that are not required, but could improve performance or user experience if supported. Nothing is missing. Everything is OK! WebGL information Version string: WebGL 2.0 (OpenGL ES 3.0 Chromium) Numeric version: 2 Supports NPOT textures: yes Supports GPU profiling: no Supports highp precision: yes Vendor: Google Inc. (NVIDIA) Renderer: ANGLE (NVIDIA, NVIDIA GeForce GTX 1650 Ti (0x00001F95) Direct3D11 vs_5_0 ps_5_0, D3D11) Major performance caveat: no Maximum texture size: 16384 Point size range: 1 to 1024 Extensions: EXT_clip_control EXT_color_buffer_float EXT_color_buffer_half_float EXT_conservative_depth EXT_depth_clamp EXT_disjoint_timer_query_webgl2 EXT_float_blend EXT_polygon_offset_clamp EXT_render_snorm EXT_texture_compression_bptc EXT_texture_compression_rgtc EXT_texture_filter_anisotropic EXT_texture_mirror_clamp_to_edge EXT_texture_norm16 KHR_parallel_shader_compile NV_shader_noperspective_interpolation OES_draw_buffers_indexed OES_sample_variables OES_shader_multisample_interpolation OES_texture_float_linear OVR_multiview2 WEBGL_blend_func_extended WEBGL_clip_cull_distance WEBGL_compressed_texture_s3tc WEBGL_compressed_texture_s3tc_srgb WEBGL_debug_renderer_info WEBGL_debug_shaders WEBGL_lose_context WEBGL_multi_draw WEBGL_polygon_mode WEBGL_provoking_vertex WEBGL_stencil_texturing Audio information System sample rate: 96000 Hz Output channels: 2 Output interpretation: speakers Supported decode formats: WebM Opus (audio/webm;codecs=opus) WebM Vorbis (audio/webm;codecs=vorbis) MPEG-4 Opus (audio/mp4;codecs=opus) MPEG-4 AAC (audio/mp4;codecs=mp4a.40.2) MP3 (audio/mpeg) FLAC (audio/flac) PCM WAV (audio/wav;codecs=1) Supported encode formats: WebM Opus (audio/webm;codecs=opus) MPEG-4 Opus (audio/mp4;codecs=opus) MPEG-4 AAC (audio/mp4;codecs=mp4a.40.2) Video information Supported decode formats: WebM AV1 (video/webm;codecs=av01.0.00M.08) WebM VP9 (video/webm;codecs=vp9) WebM VP8 (video/webm;codecs=vp8) MPEG-4 AV1 (video/mp4;codecs=av01.0.00M.08) MPEG-4 H.265 (video/mp4;codecs=hev1.1.2.L93.B0) MPEG-4 H.264 (video/mp4;codecs=avc1.420034) Supported encode formats: WebM AV1 (video/webm;codecs=av01.0.00M.08) WebM VP9 (video/webm;codecs=vp9) WebM VP8 (video/webm;codecs=vp8) WebM H.264 (video/webm;codecs=avc1.420034) MPEG-4 VP9 (video/mp4;codecs=vp9) MPEG-4 H.264 (video/mp4;codecs=avc1.420034)
AshleyScirra commented 3 months ago

Can you make a minimal project with the fewest events and objects possible as per the bug report guidelines? Anything with more than a few events is brutally difficult to debug, and this has lots of events in a deeply nested loop.

Tafubitto commented 3 months ago

Can you make a minimal project with the fewest events and objects possible as per the bug report guidelines? Anything with more than a few events is brutally difficult to debug, and this has lots of events in a deeply nested loop.

Yep! Here you go!

Array Bug 070324.zip

AshleyScirra commented 2 months ago

This appears to just be a really confusing mistake in your events involving OR blocks.

The culprit is event 5, the OR block. The system condition is always true so the OR block always runs. However the array condition is not true. When the current value is not an empty string, which is the case for every element, it unpicks the Array instance from following events. This means the following sub-events run with zero instances picked, which is a weird situation (and a regular cause of confusion with OR blocks). With zero instances picked expressions return 0 and conditions fail to run because no instance was picked to begin with, so no instance meets the conditions - so your 'else' blocks run because the previous event did not run.

So I think it's not that it's failing the same comparison - it's not making a comparison at all, because your OR block unpicked the array instance.