Forum
Contact





DirectX using C#
DirectX using C++
DirectX using Visual Basic



Latest Forum posts

 Pavtube 2014 Easter Deals with 20% off
  Posted by: VIKIVannessa
  When: 20/04/2014 at 01:35:55

 20% off on iMedia Converter for Mac
  Posted by: VIKIVannessa
  When: 20/04/2014 at 01:35:54

 Pavtube Video Converter Ultimate Deal
  Posted by: VIKIVannessa
  When: 20/04/2014 at 01:35:50

 Easter Day Deals
  Posted by: Applefly
  When: 19/04/2014 at 22:18:14

 40% OFF Pavtube DVD Ripper for Mac
  Posted by: VIKIVannessa
  When: 19/04/2014 at 02:02:54

 DVD Ripper with 40% off
  Posted by: VIKIVannessa
  When: 19/04/2014 at 02:02:22

 Get DVD Ripper Wind/Mac + $14 Coupon
  Posted by: VIKIVannessa
  When: 19/04/2014 at 02:02:03

 Backup DVD Escape Plan
  Posted by: Applefly
  When: 17/04/2014 at 06:00:12

 Disney DVDs to MP4
  Posted by: Applefly
  When: 17/04/2014 at 05:56:07

 DVD movies through media streamer
  Posted by: VIKIVannessa
  When: 16/04/2014 at 02:25:09

 DVD movies to play on Galaxy Tab 3 10.1
  Posted by: VIKIVannessa
  When: 16/04/2014 at 02:20:51

 Blu-ray to Apple ProRes
  Posted by: Applefly
  When: 12/04/2014 at 00:47:46

 HD H.264 MP4 format
  Posted by: Applefly
  When: 12/04/2014 at 00:43:23

 DVD collection to computer
  Posted by: VIKIVannessa
  When: 04/04/2014 at 07:13:33

 DVD movies to play on Galaxy Tab 3 10.1
  Posted by: VIKIVannessa
  When: 04/04/2014 at 07:11:27

 DVD movies to play on Galaxy Tab 3 10.1
  Posted by: VIKIVannessa
  When: 04/04/2014 at 07:11:27

 DVD Ripper to populate
  Posted by: Applefly
  When: 04/04/2014 at 05:01:35

 kids and family watch DVD
  Posted by: Applefly
  When: 04/04/2014 at 04:59:21

 Blu-ray movie for your lovely kids
  Posted by: VIKIVannessa
  When: 02/04/2014 at 05:47:49

 DVD to DNxHD Converter for Mac
  Posted by: VIKIVannessa
  When: 02/04/2014 at 05:46:04




Topic: Invalid casting for effects



  
Goto parent category
  
Create a new user account


   Invalid casting for effects
 Poster : BlackHawk
 Posts: 2
 Country : South Africa
 City: Cape Town

  
Posted by BlackHawk on 15/02/2007 at 00:38:16
Hi!

I get an invalid casting exception at run-time for this line of code:

foreach (BasicEffect currenteffect in mesh.Effects)

The error is that mesh.Effects is of type Effect and BasicEffect inherits from Effect.  Apparently you can't up-cast (I thought this was possible).

Any ideas?

Thanks

 Poster : peter28
 Posts: 2
 Country : Denmark
 City: Århus

  
Posted by peter28 on 20/02/2007 at 13:13:29
Same problem here. Strange
 Poster : riemer
 Posts: 1392
 Country : Belgium
 City: Antwerp

  
Posted by riemer on 20/02/2007 at 13:39:50
Do you get this error with the code presented in the tuts, or is it another project/model?
 Poster : reyjexter
 Posts: 21
 Country : philippines
 City: legazpi city

  
Posted by reyjexter on 20/02/2007 at 20:53:30
i have encoutered this error before. i think this error occurs when you set the the meshparts.Effect to the current effect you are using thus overriding the basic effect
 Poster : peter28
 Posts: 2
 Country : Denmark
 City: Århus

  
Posted by peter28 on 21/02/2007 at 04:34:49
It's the code from the tut with two changes. The model is fbx, and the shader is loaded with ContentManager.Load<Effect>(); (which shouldn't make a difference here).


foreach (ModelMesh mesh in skybox.Meshes)
    foreach (BasicEffect currenteffect in mesh.Effects)
        skyboxtextures[i++] = currenteffect.Texture;

To:             planettextures[0] = CrushEm2.ContentManager.Load<Texture2D>("Content\\Textures\\saturnmap");
            planettextures[1] = CrushEm2.ContentManager.Load<Texture2D>("Content\\Textures\\saturnringcolor");
 Poster : Anonymous
 Posts:
 Country :
 City:

  
Posted by Anonymous on 21/02/2007 at 04:40:17
Sorry. I was a bit quick there. The last code shows how the problem was solved in my case, at least with the textures.
 Poster : BlackHawk
 Posts: 2
 Country : South Africa
 City: Cape Town

  
Posted by BlackHawk on 22/02/2007 at 02:40:29
@riemer - I haven't modified the tut code.  I used it as is.  Also all your content.  

Loading the textures separately into the texture array displays them. I can't figure out the order they should go into the array so I'm not getting a smooth continuous skybox effect.
 Poster : Anonymous
 Posts:
 Country :
 City:

  
Posted by Anonymous on 05/07/2007 at 15:21:59
I had exactly the same problem and it went away after I replaced the erroneous
[code]skybox = FillModelFromFile("skybox2");[/code] with the proper [code]skybox = content.Load<Model>("skybox2");[/code].
 Poster : rong
 Posts: 8
 Country : China
 City: BeiJing

  
Posted by rong on 15/07/2008 at 03:10:04
Hi, I found same problem :(
The compiler complains about casting. I changed from

foreach (ModelMesh mesh in newModel.Meshes)
        foreach (BasicEffect currentEffect in mesh.Effects)
            textures[i++] = currentEffect.Texture;

to

_textureSky = new Texture2D[_modelSky.Meshes.Count];
            _textureSky[0] = Global.CONTENT.Load<Texture2D>(@"Skybox\skybox_top");
            _textureSky[1] = Global.CONTENT.Load<Texture2D>(@"Skybox\skybox_right");
            _textureSky[2] = Global.CONTENT.Load<Texture2D>(@"Skybox\skybox_left");
            _textureSky[3] = Global.CONTENT.Load<Texture2D>(@"Skybox\skybox_front");
            _textureSky[4] = Global.CONTENT.Load<Texture2D>(@"Skybox\skybox_back");
            _textureSky[5] = Global.CONTENT.Load<Texture2D>(@"Skybox\skybox_bottom");

  
Post a new reply
 





Google
 
Web www.riemers.net
If you appreciate the amount of time I spend creating and updating
these pages, feel free to donate -- any amount is welcome !
- Website design & DirectX code : Riemer Grootjans -
©2006 Riemer Grootjans


News
Home
Forum
XNA 2.0 Recipes Book (8)
XNA 3.0 Recipes Book (8)
Downloads
Extra Reading (3)
Matrices: geometrical
Matrix Mathematics
Homogenous matrices
Community Projects (1)
Tutorials (160)
XNA 4.0 using C# (89)
DirectX using C# (54)
Series 1:Terrain (14)
Opening a window
Linking to the Device
Drawing a triangle
Camera
Rotation - Translation
Indices
Terrain creation
Terrain from file
DirectInput
Importing bmp files
Colored vertices
DirectX Light basics
Mesh creation
Mesh lighting
Series 2: Flightsim (19)
Series 3: HLSL (19)
Short Tuts (2)
Resizing problem
Checking Device caps
DirectX using C++ (15)
DirectX using VB (2)