Cocos2DXNA / cocos2d-xna

XNA Port of Cocos2d-X
www.cocos2dxna.com
227 stars 123 forks source link

CCParticleSystem crashes on WP8 #381

Closed engmadly closed 10 years ago

engmadly commented 10 years ago

Particle System test crashes on WP8.

System.UnauthorizedAccessException was unhandled by user code HResult=-2147024891 Message=Invalid cross-thread access. Source=System.Windows StackTrace: at MS.Internal.XcpImports.CheckThread() at System.Windows.DependencyObject..ctor(UInt32 nativeTypeIndex, IntPtr constructDO) at System.Windows.Media.Imaging.WriteableBitmap..ctor(Int32 pixelWidth, Int32 pixelHeight) at Microsoft.Phone.PictureDecoder.DecodeJpegInternal(Stream source, Int32 maxPixelWidth, Int32 maxPixelHeight) at Microsoft.Phone.PictureDecoder.DecodeJpeg(Stream source) at Microsoft.Xna.Framework.Graphics.Texture2D.<>cDisplayClass3.b2() at Microsoft.Xna.Framework.Threading.BlockOnUIThread(Action action) at Microsoft.Xna.Framework.Graphics.Texture2D.FromStream(GraphicsDevice graphicsDevice, Stream stream) at Cocos2D.CCTexture2D.LoadTexture(Stream stream, CCImageFormat imageFormat) at Cocos2D.CCTexture2D.LoadTexture(Stream stream) at Cocos2D.CCTexture2D.InitWithData(Byte[] data, SurfaceFormat pixelFormat, Boolean mipMap) at Cocos2D.CCTexture2D.InitWithData(Byte[] data, SurfaceFormat pixelFormat) at Cocos2D.CCTextureCache.AddImage(Byte[] data, String assetName, SurfaceFormat format) at Cocos2D.CCParticleExample.get_DefaultTexture() at Cocos2D.CCParticleSystem.InitWithDictionary(PlistDictionary dictionary) at Cocos2D.CCParticleSystem.InitWithFile(String plistFile) at Cocos2D.CCParticleSystem..ctor(String plistFile) at Cocos2D.CCParticleSystemQuad..ctor(String plistFile) at tests.ParticleReorder.OnEnter() at Cocos2D.CCNode.OnEnter() at tests.TestScene.OnEnter() at Cocos2D.CCDirector.SetNextScene() at Cocos2D.CCDirector.Update(GameTime gameTime) at Cocos2D.CCApplication.Update(GameTime gameTime) at Microsoft.Xna.Framework.Game.<.cctor>b__19(IUpdateable updateable, GameTime gameTime) at Microsoft.Xna.Framework.Game.SortingFilteringCollection1.ForEachFilteredItem[TUserData](Action2 action, TUserData userData) at Microsoft.Xna.Framework.Game.Update(GameTime gameTime) at TestWin8Phone.Game1.Update(GameTime gameTime) at Microsoft.Xna.Framework.Game.DoUpdate(GameTime gameTime) at Microsoft.Xna.Framework.Game.Tick() at MonoGame.Framework.WindowsPhone.SurfaceUpdateHandler.Draw(Device device, DeviceContext context, RenderTargetView renderTargetView) at MonoGame.Framework.WindowsPhone.DrawingSurfaceUpdateHandler.DrawingSurfaceContentProvider.GetTexture(Size2F surfaceSize, DrawingSurfaceSynchronizedTexture& synchronizedTexture, RectangleF& textureSubRectangle) at SharpDX.Direct3D11.DrawingSurfaceContentProviderShadow.DrawingSurfaceContentProviderVtbl.GetTexture(IntPtr thisPtr, IntPtr surfaceSize, IntPtr synchronizedTexture, IntPtr textureSubRectangle) InnerException:

totallyeviljake commented 10 years ago

Is this still happening with the latest 1.3.0.2 release?

netonjm commented 10 years ago

Seems to be a problem invoking the Particle System (on the "new") on a ilegal thread call. Try invoke it in a safe static context:

Deployment.Current.Dispatcher.BeginInvoke(() => { var magicParticleWorking = new CC ....(); ... });

totallyeviljake commented 10 years ago

ParticleSystemTest : Reordering partlcles, this one works for me on the simulator.

totallyeviljake commented 10 years ago

Particle Batch test works too

totallyeviljake commented 10 years ago

The 4th test appears to have this cross-thread error. This is the ParticleFlower test.

totallyeviljake commented 10 years ago

I have it fixed. will push it up to our fork of monogame.

totallyeviljake commented 10 years ago

This is fixed now.

pawelklimczyk commented 10 years ago

I'm not sure if this is fixed... I try to create new CCParticleExplosion() and I got "Invalid cross-thread access." here: writableBitmap = Microsoft.Phone.PictureDecoder.DecodeJpeg(stream); in Texture2D.cs line 841. I have my source code updated.

What I've figured out is that assigning the Texture inside CCParticleExplosion InitWithTotalParticles causes the problem. Creating texture FromStream throws this exception.... not sure how to fix that in cocos2d-xna source code...

netonjm commented 10 years ago

Have you tried to create the CCParticleExplosion in:

Deployment.Current.Dispatcher.BeginInvoke(() => { CCParticleExplosion explosion = new CCParticleExplosion(); ... });

??

totallyeviljake commented 10 years ago

yes, I tried all of the test cases that we have in the suite. They all worked without problems.

pawelklimczyk commented 10 years ago

My code crashes when running on Lumia 925. Maybe it is only an issue on actual devices.

pawelklimczyk commented 10 years ago

I have run the original tests on my device and everything works... so there must be an issue in my code, but I'm not able to track it. The code in both cases is executed in "worker thread" and that causes exception and, finally crash, in my code.

I'll investigate that deeper later. For now I don't know where the issue could be.

totallyeviljake commented 10 years ago

I have both a lumia 8 and 9 series phone. I will try them both again to see if they suffer similar problems. I found the 9 series does behave differently than the 8. There is a fix to the WP8 template that appears to have fixed the deadlock issue another user had. Maybe something similar is in order for you - to move the game construction to the Loaded even handler instead of in the game page xaml ctor.

pawelklimczyk commented 10 years ago

I'll try. For now I think this case can be closed.