我是新来的多线程,所以暂时搁置所有其他问题。我在解决我的sprite批处理问题时遇到了困难,因为更快的线程和下一个线程导致“对象引用未设置为对象的实例”。C#XNA多线程SpriteBatch.End()“对象引用未设置为对象的实例”
哦,如果你能看到什么都错我的代码随意让我觉得自己像个白痴^^
spriteBatch.Begin();
// Draw Particles
List<Thread> threads = new List<Thread>();
for (int i = 0; i < CPUCores; i++)
{
int tempi = i; // This fixes the issue with i being shared
Thread thread = new Thread(() => DrawParticles(tempi + 1, CPUCores));
threads.Add(thread);
thread.Start();
}
foreach (var thread in threads)
{
thread.Join();
}
// ..More Drawing Code..
spriteBatch.End(); // <-- This is where the program crashes
PS是谁决定了它是使用4个空格来表示代码,而不是一个好主意[code] [/ code]的? ¬_¬
欢迎来到StackOverflow :-)帖子的格式使用Markdown(我觉得这很不错),所以这就是4格式的来源。有关更多详细信息,请参阅http://stackoverflow.com/editing-help。 –