Creating an NRaas project Spawning a dialog via reflection

Talk nerdy to us here.
Post Reply
User avatar
Chain_Reaction
Site Admin
Reactions:
Posts: 7568
Joined: December 30th, 2011, 6:00 pm
Answers: 81
Contact:

Spawning a dialog via reflection

Post by Chain_Reaction » December 20th, 2015, 3:53 am

In the event anyone else is trying to spawn a dialog via invocation/reflection (probably no one ever, only I find myself in these situations), the game apparently doesn't like this (if you set it to pause the simulator which all twallan dialogs are). You get:

<!-- ws:start:WikiTextCodeRule:0:
<pre class="text">System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. &#45;&#45;-&gt; System.NotSupportedException: Attempting to yield in a non-yielding context!<br/>#0: 0x00043 sim_sleep in Sims3.UI.Sims3.UI.ModalDialog:Pause () ()<br/>#1: 0x000ad callvirt in Sims3.UI.Sims3.UI.ModalDialog:StartModal (bool) (3DCC8E40 [1] )<br/>#2: 0x00002 callvirt in Sims3.UI.Sims3.UI.ModalDialog:StartModal () </pre>
-->
<style type="text/css"><!--
/**
* GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann
* (http://qbnz.com/highlighter/ and http://geshi.org/)
*/
.text {font-family:monospace;}
.text .imp {font-weight: bold; color: red;}
.text span.xtra { display:block; }

-->
</style><pre class="text">System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NotSupportedException: Attempting to yield in a non-yielding context!
#0: 0x00043 sim_sleep in Sims3.UI.Sims3.UI.ModalDialog:Pause () ()
#1: 0x000ad callvirt in Sims3.UI.Sims3.UI.ModalDialog:StartModal (bool) (3DCC8E40 [1] )
#2: 0x00002 callvirt in Sims3.UI.Sims3.UI.ModalDialog:StartModal () </pre>


Because the simulator cannot yield a task that is coming in via reflection.

Rather than you banging your head for 2 days like I've been doing, here's the solution: use a delayed alarm to spawn it. Invoke a function that sets the alarm and then make the alarm spawn the dialog. Solved. You're welcome.

This finding brought to you by many hours of trying to get filterable mods to spawn MC's filter dialog.