c# - XNA/Mono Effect Throwing Runtime Cast Exception -
as foreword, exact same code works fine in xna, monogame throws exception. requires familiar monogame rendering pipeline.
during draw section of game, there's shadowmapresolver renders out texture final calculated light pattern given light. it's receiving exception when rendering effectpass.apply()
complaining somewhere within mono theres attempted cast int32[]
single[]
. here's code calls it:
private void executetechnique(texture2d source, rendertarget2d destination, string techniquename, texture2d shadowmap) { graphicsdevice.setrendertarget(destination); graphicsdevice.clear(color.transparent); resolveshadowseffect.parameters["rendertargetsizex"].setvalue((float)basesizex); resolveshadowseffect.parameters["rendertargetsizey"].setvalue((float)basesizey); if (source != null) resolveshadowseffect.parameters["inputtexture"].setvalue(source); if (shadowmap != null) resolveshadowseffect.parameters["shadowmaptexture"].setvalue(shadowmap); resolveshadowseffect.currenttechnique = resolveshadowseffect .techniques[techniquename]; try { foreach (effectpass pass in resolveshadowseffect.currenttechnique.passes) { pass.apply(); // <--- invalidcastexception re-enters program here quadrender.render(vector2.one * -1, vector2.one); } } catch (exception ex) { util.log(logmanager.loglevel.critical, ex.message); } graphicsdevice.setrendertarget(null); }
and here stacktrace:
at microsoft.xna.framework.graphics.constantbuffer.setdata(int32 offset, int32 rows, int32 columns, object data) @ microsoft.xna.framework.graphics.constantbuffer.setparameter(int32 offset, effectparameter param) @ microsoft.xna.framework.graphics.constantbuffer.update(effectparametercollection parameters) @ microsoft.xna.framework.graphics.effectpass.apply() @ jasg.shadowmapresolver.executetechnique(texture2d source, rendertarget2d destination, string techniquename, texture2d shadowmap) in c:\users\[snip]\dropbox\projects\jasg2\jasg\jasg\rendering\shadowmapresolver.cs:line 253
so appear 1 of parameters of shader trying set confusing monogame somehow, don't see be. i'm pushing floats, not int arrays. tried changing rendertarget2d.surfaceformat
color single targets , textures, still gives exact same error.
outside of function gave, in broader scope, there no other parameters being set since effectpass.apply
. there multiple other effects render without error before one.
in case helps, here's source monogame framework regarding constantbuffer.setdata()
private void setdata(int offset, int rows, int columns, object data) { // shader registers 4 bytes , // incoming data objects should 4 bytes per element. const int elementsize = 4; const int rowsize = elementsize * 4; // take care of single element. if (rows == 1 && columns == 1) { // effectparameter stores values in arrays default. if (data array) buffer.blockcopy(data array, 0, _buffer, offset, elementsize); else { // todo: when expose internal shader // api need deal non-array elements. throw new notimplementedexception(); } } // take care of single copy case! else if (rows == 1 || (rows == 4 && columns == 4)) buffer.blockcopy(data array, 0, _buffer, offset, rows*columns*elementsize); else { var source = data array; var stride = (columns*elementsize); (var y = 0; y < rows; y++) buffer.blockcopy(source, stride*y, _buffer, offset + (rowsize*y), columns*elementsize); } }
is sort of marshaling problem? time!
edit: p.s.: exception invalidcastexception
, not notimplementedexception
.
not sure if helps or not casting see being done data array. bet crashing on line :
buffer.blockcopy(data array, 0, _buffer, offset, rows*columns*elementsize);
or
var source = data array;
because don't type checking before casting there. if line crashing on because don't seem support non-array data values. don't know framework enough give solid answer on how work around this. report bug makers here
Comments
Post a Comment