@@ -1068,40 +1068,48 @@ protected virtual void OnEnable()
10681068 ExplorerCore . LogWarning ( $ "Failed to listen to BeforeRender: { exception } ") ;
10691069 }
10701070#endif
1071- // These doesn't exist for Unity <2017 nor when using HDRP
1072- Type renderPipelineManagerType = ReflectionUtility . GetTypeByName ( "RenderPipelineManager" ) ;
1073- if ( renderPipelineManagerType != null ) {
1074- EventInfo beginFrameRenderingEvent = renderPipelineManagerType . GetEvent ( "beginFrameRendering" ) ;
1075- if ( beginFrameRenderingEvent != null ) {
1076- beginFrameRenderingEvent . AddEventHandler ( null , OnBeforeEvent ) ;
1077- }
1078- EventInfo endFrameRenderingEvent = renderPipelineManagerType . GetEvent ( "endFrameRendering" ) ;
1079- if ( endFrameRenderingEvent != null ) {
1080- endFrameRenderingEvent . AddEventHandler ( null , OnAfterEvent ) ;
1081- }
10821071
1083- EventInfo beginCameraRenderingEvent = renderPipelineManagerType . GetEvent ( "beginCameraRendering" ) ;
1084- if ( beginCameraRenderingEvent != null ) {
1085- beginCameraRenderingEvent . AddEventHandler ( null , OnBeforeEvent ) ;
1086- }
1087- EventInfo endCameraRenderingEvent = renderPipelineManagerType . GetEvent ( "endCameraRendering" ) ;
1088- if ( endCameraRenderingEvent != null ) {
1089- endCameraRenderingEvent . AddEventHandler ( null , OnAfterEvent ) ;
1090- }
1072+ try
1073+ {
1074+ // These doesn't exist for Unity <2017 nor when using HDRP
1075+ Type renderPipelineManagerType = ReflectionUtility . GetTypeByName ( "RenderPipelineManager" ) ;
1076+ if ( renderPipelineManagerType != null ) {
1077+ EventInfo beginFrameRenderingEvent = renderPipelineManagerType . GetEvent ( "beginFrameRendering" ) ;
1078+ if ( beginFrameRenderingEvent != null ) {
1079+ beginFrameRenderingEvent . AddEventHandler ( null , OnBeforeEvent ) ;
1080+ }
1081+ EventInfo endFrameRenderingEvent = renderPipelineManagerType . GetEvent ( "endFrameRendering" ) ;
1082+ if ( endFrameRenderingEvent != null ) {
1083+ endFrameRenderingEvent . AddEventHandler ( null , OnAfterEvent ) ;
1084+ }
10911085
1092- EventInfo beginContextRenderingEvent = renderPipelineManagerType . GetEvent ( "beginContextRendering" ) ;
1093- if ( beginContextRenderingEvent != null ) {
1094- beginContextRenderingEvent . AddEventHandler ( null , OnBeforeEvent ) ;
1086+ EventInfo beginCameraRenderingEvent = renderPipelineManagerType . GetEvent ( "beginCameraRendering" ) ;
1087+ if ( beginCameraRenderingEvent != null ) {
1088+ beginCameraRenderingEvent . AddEventHandler ( null , OnBeforeEvent ) ;
1089+ }
1090+ EventInfo endCameraRenderingEvent = renderPipelineManagerType . GetEvent ( "endCameraRendering" ) ;
1091+ if ( endCameraRenderingEvent != null ) {
1092+ endCameraRenderingEvent . AddEventHandler ( null , OnAfterEvent ) ;
1093+ }
1094+
1095+ EventInfo beginContextRenderingEvent = renderPipelineManagerType . GetEvent ( "beginContextRendering" ) ;
1096+ if ( beginContextRenderingEvent != null ) {
1097+ beginContextRenderingEvent . AddEventHandler ( null , OnBeforeEvent ) ;
1098+ }
1099+ EventInfo endContextRenderingEvent = renderPipelineManagerType . GetEvent ( "endContextRendering" ) ;
1100+ if ( endContextRenderingEvent != null ) {
1101+ endContextRenderingEvent . AddEventHandler ( null , OnAfterEvent ) ;
1102+ }
10951103 }
1096- EventInfo endContextRenderingEvent = renderPipelineManagerType . GetEvent ( "endContextRendering" ) ;
1097- if ( endContextRenderingEvent != null ) {
1098- endContextRenderingEvent . AddEventHandler ( null , OnAfterEvent ) ;
1104+
1105+ EventInfo onBeforeRenderEvent = typeof ( Application ) . GetEvent ( "onBeforeRender" ) ;
1106+ if ( onBeforeRenderEvent != null ) {
1107+ onBeforeRenderEvent . AddEventHandler ( null , onBeforeRenderAction ) ;
10991108 }
11001109 }
1101-
1102- EventInfo onBeforeRenderEvent = typeof ( Application ) . GetEvent ( "onBeforeRender" ) ;
1103- if ( onBeforeRenderEvent != null ) {
1104- onBeforeRenderEvent . AddEventHandler ( null , onBeforeRenderAction ) ;
1110+ catch ( Exception exception )
1111+ {
1112+ ExplorerCore . LogWarning ( $ "Failed to add event handler to rendering pipeline: { exception } ") ;
11051113 }
11061114 }
11071115
@@ -1117,41 +1125,48 @@ protected virtual void OnDisable()
11171125 ExplorerCore . LogWarning ( $ "Failed to unlisten from BeforeRender: { exception } ") ;
11181126 }
11191127#endif
1120- // These doesn't exist for Unity <2017 nor when using HDRP
1121- Type renderPipelineManagerType = ReflectionUtility . GetTypeByName ( "RenderPipelineManager" ) ;
11221128
1123- if ( renderPipelineManagerType != null ) {
1124- EventInfo beginFrameRenderingEvent = renderPipelineManagerType . GetEvent ( "beginFrameRendering" ) ;
1125- if ( beginFrameRenderingEvent != null ) {
1126- beginFrameRenderingEvent . RemoveEventHandler ( null , OnBeforeEvent ) ;
1127- }
1128- EventInfo endFrameRenderingEvent = renderPipelineManagerType . GetEvent ( "endFrameRendering" ) ;
1129- if ( endFrameRenderingEvent != null ) {
1130- endFrameRenderingEvent . RemoveEventHandler ( null , OnAfterEvent ) ;
1131- }
1129+ try
1130+ {
1131+ // These doesn't exist for Unity <2017 nor when using HDRP
1132+ Type renderPipelineManagerType = ReflectionUtility . GetTypeByName ( "RenderPipelineManager" ) ;
1133+ if ( renderPipelineManagerType != null ) {
1134+ EventInfo beginFrameRenderingEvent = renderPipelineManagerType . GetEvent ( "beginFrameRendering" ) ;
1135+ if ( beginFrameRenderingEvent != null ) {
1136+ beginFrameRenderingEvent . RemoveEventHandler ( null , OnBeforeEvent ) ;
1137+ }
1138+ EventInfo endFrameRenderingEvent = renderPipelineManagerType . GetEvent ( "endFrameRendering" ) ;
1139+ if ( endFrameRenderingEvent != null ) {
1140+ endFrameRenderingEvent . RemoveEventHandler ( null , OnAfterEvent ) ;
1141+ }
11321142
1133- EventInfo beginCameraRenderingEvent = renderPipelineManagerType . GetEvent ( "beginCameraRendering" ) ;
1134- if ( beginCameraRenderingEvent != null ) {
1135- beginCameraRenderingEvent . RemoveEventHandler ( null , OnBeforeEvent ) ;
1136- }
1137- EventInfo endCameraRenderingEvent = renderPipelineManagerType . GetEvent ( "endCameraRendering" ) ;
1138- if ( endCameraRenderingEvent != null ) {
1139- endCameraRenderingEvent . RemoveEventHandler ( null , OnAfterEvent ) ;
1140- }
1143+ EventInfo beginCameraRenderingEvent = renderPipelineManagerType . GetEvent ( "beginCameraRendering" ) ;
1144+ if ( beginCameraRenderingEvent != null ) {
1145+ beginCameraRenderingEvent . RemoveEventHandler ( null , OnBeforeEvent ) ;
1146+ }
1147+ EventInfo endCameraRenderingEvent = renderPipelineManagerType . GetEvent ( "endCameraRendering" ) ;
1148+ if ( endCameraRenderingEvent != null ) {
1149+ endCameraRenderingEvent . RemoveEventHandler ( null , OnAfterEvent ) ;
1150+ }
11411151
1142- EventInfo beginContextRenderingEvent = renderPipelineManagerType . GetEvent ( "beginContextRendering" ) ;
1143- if ( beginContextRenderingEvent != null ) {
1144- beginContextRenderingEvent . RemoveEventHandler ( null , OnBeforeEvent ) ;
1152+ EventInfo beginContextRenderingEvent = renderPipelineManagerType . GetEvent ( "beginContextRendering" ) ;
1153+ if ( beginContextRenderingEvent != null ) {
1154+ beginContextRenderingEvent . RemoveEventHandler ( null , OnBeforeEvent ) ;
1155+ }
1156+ EventInfo endContextRenderingEvent = renderPipelineManagerType . GetEvent ( "endContextRendering" ) ;
1157+ if ( endContextRenderingEvent != null ) {
1158+ endContextRenderingEvent . RemoveEventHandler ( null , OnAfterEvent ) ;
1159+ }
11451160 }
1146- EventInfo endContextRenderingEvent = renderPipelineManagerType . GetEvent ( "endContextRendering" ) ;
1147- if ( endContextRenderingEvent != null ) {
1148- endContextRenderingEvent . RemoveEventHandler ( null , OnAfterEvent ) ;
1161+
1162+ EventInfo onBeforeRenderEvent = typeof ( Application ) . GetEvent ( "onBeforeRender" ) ;
1163+ if ( onBeforeRenderEvent != null ) {
1164+ onBeforeRenderEvent . RemoveEventHandler ( null , onBeforeRenderAction ) ;
11491165 }
11501166 }
1151-
1152- EventInfo onBeforeRenderEvent = typeof ( Application ) . GetEvent ( "onBeforeRender" ) ;
1153- if ( onBeforeRenderEvent != null ) {
1154- onBeforeRenderEvent . RemoveEventHandler ( null , onBeforeRenderAction ) ;
1167+ catch ( Exception exception )
1168+ {
1169+ ExplorerCore . LogWarning ( $ "Failed to remove event handler from rendering pipeline: { exception } ") ;
11551170 }
11561171 }
11571172
0 commit comments