Select to view content in your preferred language

Crash accessing textureCoord2 on scene layer RaycastHit

255
0
11-19-2024 04:41 AM
Thomas-F
Occasional Contributor

Hi,

I'm encountering a crash when using Unity's `RaycastHit.textureCoord2` property exclusively when raycasting against scene layers.

Example:

RaycastHit hit;
if (Physics.Raycast(rayOrigin, rayDirection, out hit))
{
    var texCoord2 = hit.textureCoord2; // Crash in textureCoord2 access
}

Does anyone have experience with this issue and have any suggestions on how to avoid a crash while still being able to raycast against scene layers and access `textureCoord2` (in case the hit is not an ArcGIS scene layer and I do need to use `RaycastHit.textureCoord2` for other potential hits)?

Note: I suspect this could be related to the fact that scene layer meshes have feature indices in uv channel 1, which consist of a single float value rather than a `Vector2`.

Example excerpt of Unity editor logs showing crash details:

=================================================================
	Native Crash Reporting
=================================================================
Got a UNKNOWN while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

=================================================================
	Managed Stacktrace:
=================================================================
	  at <unknown> <0xffffffff>
	  at UnityEngine.RaycastHit:CalculateRaycastTexCoord_Injected <0x0013e>
	  at UnityEngine.RaycastHit:CalculateRaycastTexCoord <0x000b2>
	  at UnityEngine.RaycastHit:get_textureCoord2 <0x0012a>
	  at Raycaster:Update <0x003b2>
	  at System.Object:runtime_invoke_void__this__ <0x00187>
=================================================================
Received signal SIGSEGV

 Unity version: 2022.3.52f

0 Kudos
0 Replies