I am in the final stages of porting some code into my framework.
The latest problem is very similar to this one I posted recently ( Strange "The type arguments for method cannot be inferred from the usage." ), whereby text enclosed in '<' and '>' in the listing I am porting code is missing.
The latest offending line is:
using (var resource = SlimDX.Direct3D11.Resource.FromSwapChain(swapChain, 0))
renderTarget = new SlimDX.Direct3D11.RenderTargetView(graphics, resource);
I get the following error from the compiler:
The type arguments for method 'SlimDX.Direct3D10.Device.OpenSharedResource(System.IntPtr)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
I tried to fix this myself by changing my code to:
using (var resource = SlimDX.Direct3D11.Resource.FromSwapChain<SlimDX.Direct3D11.Resource>(swapChain, 0))
renderTarget = new SlimDX.Direct3D11.RenderTargetView(graphics, resource);
... but now I get an even stranger run-time error:
"Error: Method 'SlimDX.Direct3D11.Resource.FromPointerReflectionThunk' not found."
Initial research indicates I might have stumbled into something which is way above my head: http://www.gamedev.net/topic/542095-slimdx-need-help-from-nativemanaged-interop-expert/
All I am trying to do is port this code into my framework: http://www.aaronblog.us/?p=36 ... which is all about drawing text in SlimDX with DX11.
At some point I hope to have figured out how to genericise this code into my framework. It is heavy going though.
I'm using SlimDX SDK (January 2012).
Look at the last post in the gamedev.net thread you referenced -- it says that you can fix the problem by specifying the type argument as Texture2D.
So you might try:
using (var resource = SlimDX.Direct3D11.Resource.FromSwapChain<Texture2D>(swapChain, 0))
renderTarget = new SlimDX.Direct3D11.RenderTargetView(graphics, resource);
Related
i've been using this wonderful library for low impact screen recording software however im at a point where i need to use a DirectX Scale Effect to scale the image down with anisotropic filtering.
I can create the effect just fine and set up most of its parameters, however im not able to set the most important one for me scaleEffect.SetValue((int)ScaleProperties.InterpolationMode, (int)SharpDX.Direct2D1.ScaleInterpolationMode.Anisotropic);
As soon as the program runs it crashes at that line with an invalid parameter exception.
I've searched and couldnt find anything wrong with the code, but then again i have almost 0 experience with anything Direct2D.
Here is the full code for that specific effect for reference:
SharpDX.Direct2D1.Effect scaleEffect = new D2D.Effect(textureDc, D2D.Effect.Scale);
scaleEffect.Cached = true;
scaleEffect.SetInput(0, frameBitmap, false);
var centerPoint = new SharpDX.Vector2(0, 0);
var newSize = new SharpDX.Vector2(0.2f, 0.2f);
scaleEffect.SetValue((int)ScaleProperties.CenterPoint, centerPoint);
scaleEffect.SetValue((int)ScaleProperties.Scale, newSize);
//Crashes Here: scaleEffect.SetValue((int)ScaleProperties.InterpolationMode, (int)SharpDX.Direct2D1.ScaleInterpolationMode.Anisotropic);
Error Message: SharpDX.SharpDXException: 'HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: The parameter is incorrect.'
textureDc.BeginDraw();
textureDc.DrawImage(scaleEffect, InterpolationMode.Anisotropic);
textureDc.EndDraw();
Thank you very much in advance for any help!
UPDATE:
As per #Simon Mourier comment, the solution to avoid this bug somewhere in the SharpDX API, is to use the SharpDX.Direct2D1.Effects.Scale instead.
This way, i can confirm the InterpolationMode does no longer crash and works as intended!
Here is the new, working code for anyone running into the same issue.
SharpDX.Direct2D1.Effects.Scale scaleClass = new D2D.Effects.Scale(textureDc);
scaleClass.SetInput(0, frameBitmap,false);
scaleClass.Cached = true;
var centerPoint = new SharpDX.Vector2(0, 0);
var newSize = new SharpDX.Vector2(0.2f, 0.2f);
scaleClass.CenterPoint = centerPoint;
scaleClass.ScaleAmount = newSize;
scaleClass.InterpolationMode = InterpolationMode.Anisotropic;
textureDc.BeginDraw();
textureDc.DrawImage(scaleClass);
textureDc.EndDraw();
PS: For anyone wondering about casting the value to uint instead using the first method, it returns the following error:
(Argument1 cannot convert from uint to int)
So it semms that there might be some underlying bug in this specific scenario.
One solution is to use the SharpDX.Direct2D1.Effects.Scale directly which is a wrapper over the Effect class and comes with an InterpolationMode property.
I'm working on an application for bulk parsing and uploading to an AllegroGraph triplestore, but have run into a snag. I am able to open and read the graph in question using the below code:
AllegroGraphConnector conn = new AllegroGraphConnector(myHost, myGraph, myUsername, myPassword);
Graph g = new Graph();
conn.LoadGraph(g, "");
g.BaseUri = new Uri(MOG);
foreach (RTSNode r in _nodes)
{
IUriNode sbj = g.CreateUriNode(new Uri(RTSuri + r.myName));
IUriNode pred = g.CreateUriNode(new Uri(MOG));
ILiteralNode obj = g.CreateLiteralNode(r.myName, "en");
g.Assert(new Triple(sbj, pred, obj));
}
conn.SaveGraph(g);
As mentioned the graph loads fine and triples are being added to the local version. But when I attempt to save it, I get an 400- Bad request error. Turning on full debugging shows the error to be due to:
UNSUPPORTED FILE FORMAT: 'application/n-triples' is not a supported content-type
Is there an option for changing the default format with which AllegroGraphConnector communicates?
Thank you for your time.
What version of dotNetRDF are you using?
This sounds like a bug which was fixed in our recent 1.0.8 release so I would first try upgrading to the latest version which should resolve the issue
Update
So it looks like this is a bug in AllegroGraph, according to their documentation they are expecting the MIME type for NTriples to be text/plain whereas most current systems (including dotNetRDF) use the now standard application/n-triples as the MIME type for NTriples.
Currently there is no workaround for this, filed as CORE-447 to be fixed for the next release
Today I updated to Xamarin.iOS 8.6.0.51 and switched to the new Unified API.
Now I want to get the keyboard size (this code worked before):
var val = new NSValue (notification.UserInfo.ValueForKey (UIKeyboard.FrameBeginUserInfoKey).Handle);
RectangleF keyboardSize = val.RectangleFValue;
With the help of the migration tool the RectangleF is converted to CGRect, but the errors I'm getting here are
Error CS1540: Cannot access protected member
Foundation.NSValue.NSValue(System.IntPtr)' via a qualifier of type
Foundation.NSValue'. The qualifier must be of type
`MyApp.SomeViewController' or derived from it (CS1540)
and
Error CS0122: `Foundation.NSValue.NSValue(System.IntPtr)' is
inaccessible due to its protection level (CS0122)
How can I solve this? I can delete new NSValue(...), but RectangleFValue still doesn't work and I would need a replacement/another way.
Edit:
According to jonathanpeppers I modified my code to:
NSValue keyboardFrameBegin = (NSValue)notification.UserInfo.ValueForKey (UIKeyboard.FrameBeginUserInfoKey);
CGRect keyboardSize = keyboardFrameBegin.CGRectValue;
This doesn't throw an error anymore, but I can't test it further because I'm in the process of migrating to the Unified API and there are still some errors to correct.
Can you just use a cast:
var val = (NSValue)notification.UserInfo.ValueForKey (UIKeyboard.FrameBeginUserInfoKey);
RectangleF keyboardSize = val.RectangleFValue;
Only rarely should you have to mess with handles in Xamarin.iOS.
To be absolutely sure what to cast to, debug and see what the underlying type is first:
NSObject val = notification.UserInfo.ValueForKey (UIKeyboard.FrameBeginUserInfoKey);
Console.WriteLine("Type: " + val.GetType());
The .ctor(IntPtr) constructors in NSObject could be misused and causes issue later. Also, like #jonathanpeppers mentioned, they were not required for many scenarios (like this one).
Another way to do this (e.g. if you have nothing else but an handle), as documented here, is to use the ObjCRuntime.Runtime.GetNSObject<T> (IntPtr) method. That will ensure the NSObject-subclass is created correctly.
Update: I downloaded Ramone project, added it to my project and then ran the application again with debugger. The error is shown below:
public MediaTypeWriterRegistration GetWriter(Type t, MediaType mediaType)
{
...
CodecEntry entry = SelectWriters(t, mediaType).FirstOrDefault(); => this line throws error
...
}
Error occurs in CodecManager.cs. I am trying to figure out why it does not recognize json-patch media type. Could it be because writer is not being registered correctly? I am looking into it. If you figure out the problem, please let me know. Since you are the author of the library, it will be easier for you to figure out the issue. I will have to go through all the code files and methods to find the issue. Thanks!
I was excited to know that Ramone library supports json-patch operations but when I tried it, I got following error:
415- Unsupported Media Type
This is the same error that I get when I use RestSharp. I thought may be RestSharp does not support json-patch and errors out so I decided to try Ramone lib but I still get same error. Endpoint has no issues because when I try same command using Postman, it works but when I try it programmatically in C#, it throws unsupported media type error. Here is my code:
var authenticator = new TokenProvider("gfdsfdsfdsafdsafsadfsdrj5o97jgvegh", "sadfdsafdsafdsfgfdhgfhehrerhgJ");
JsonPatchDocument patch = new JsonPatchDocument<MetaData>();
patch.Add("/Resident2", "Boyle");
//patch.Replace("/Resident", "Boyle");
RSession = RamoneConfiguration.NewSession(new Uri("https://api.box.com"));
RSession.DefaultRequestMediaType = MediaType.ApplicationJson;
RSession.DefaultResponseMediaType = MediaType.ApplicationJson;
Ramone.Request ramonerequest = RSession.Bind("/2.0/files/323433290812/metadata");
ramonerequest.Header("Authorization", "Bearer " + authenticator.GetAccessToken(code).AccessToken);
//var ramoneresponse = ramonerequest.Patch(patch); //results in error: 405 - Method Not Allowed
var ramoneresponse = ramonerequest.Put(patch); //results in error: 415 - Unsupported Media Type
var responsebody = ramoneresponse.Body
Endpoint information is available here: http://developers.box.com/metadata-api
I used json-patch section in the following article as a reference:
http://elfisk.dk/Ramone/Documentation/Ramone.pdf
By the way I tried Patch() method (as shown in above ref. article) but that resulted in "Method not allowed" so I used Put() method which seems to work but then errors out because of json-patch operation.
Any help, guidance, tips in resolving this problem will be highly appreciated. Thanks much in advance.
-Sham
The Box documentation says you should use PUT (which is quite a bit funny). The server even tells you that it doesn't support the HTTP PATCH method (405 Method Not Allowed) - so PUT it must be.
Now, you tell Ramone to use JSON all the time (RSession.DefaultRequestMediaType = MediaType.ApplicationJson), so you end up PUT'ing a JSON document to Box - where you should be PUT'ing a JSON-Patch document.
Drop the "RSession.DefaultRequestMediaType = MediaType.ApplicationJson" statement and send the patch document as JSON-Patch with the use of: ramonerequest.ContentType("application/json-patch+json").Put(...).
My plan:
I'm trying to setup my C# project to communicate with Nodebox to call a certain function which populates a graph and draws it in a new window.
Current situation: [fixed... see Update2]
I have already included all python-modules needed, but im still getting a
Library 'GL' not found
it seems that the pyglet module needs a reference to GL/gl.h, but can't find it due to IronPython behaviour.
Requirement:
The project needs to stay as small as possible without installing new packages. Thats why i have copied all my modules into the project-folder and would like to keep it that or a similar way.
My question:
Is there a certain workaround for my problem or a fix for the library-folder missmatch.
Have read some articles about Tao-Opengl and OpenTK but can't find a good solution.
Update1:
Updated my sourcecode with a small pyglet window-rendering example. Problem is in pyglet and referenced c-Objects. How do i include them in my c# project to be called? No idea so far... experimenting alittle now. Keeping you updated.
SampleCode C#:
ScriptRuntimeSetup setup = Python.CreateRuntimeSetup(null);
ScriptRuntime runtime = new ScriptRuntime(setup);
ScriptEngine engine = Python.GetEngine(runtime);
ScriptSource source = engine.CreateScriptSourceFromFile("test.py");
ScriptScope scope = engine.CreateScope();
source.Execute(scope);
SampleCode Python (test.py):
from nodebox.graphics import *
from nodebox.graphics.physics import Vector, Boid, Flock, Obstacle
flock = Flock(50, x=-50, y=-50, width=700, height=400)
flock.sight(80)
def draw(canvas):
canvas.clear()
flock.update(separation=0.4, cohesion=0.6, alignment=0.1, teleport=True)
for boid in flock:
push()
translate(boid.x, boid.y)
scale(0.5 + boid.depth)
rotate(boid.heading)
arrow(0, 0, 15)
pop()
canvas.size = 600, 300
def main(canvas):
canvas.run(draw)
Update2:
Line 139 [pyglet/lib.py] sys.platform is not win32... there was the error. Fixed it by just using the line:
from pyglet.gl.lib_wgl import link_GL, link_GLU, link_WGL
Now the following Error:
'module' object has no attribute '_getframe'
Kind of a pain to fix it. Updating with results...
Update3:
Fixed by adding following line right after first line in C#-Code:
setup.Options["Frames"] = true;
Current Problem:
No module named unicodedata, but in Python26/DLLs is only a *.pyd file`. So.. how do i implement it now?!
Update4:
Fixed by surfing: link text and adding unicodedata.py and '.pyd to C# Projectfolder.
Current Problem:
'libGL.so not found'... guys.. im almost giving up on nodebox for C#.. to be continued
Update5:
i gave up :/ workaround: c# communicating with nodebox over xml and filesystemwatchers. Not optimal, but case solved.
-X:Frames enables the frames option as runtime (it slows code down a little to have access to the Python frames all the time).
To enable frames when hosting you just need to do:
ScriptRuntimeSetup setup = Python.CreateRuntimeSetup(new Dictionary<string, object>() {
{ "Frames", true }
});
Instead of the null that you're passing now. That's just creating a new dictionary for the options dictionary w/ the contents "Frames" set to true. You can set other options in there as well and in general the -X:Name option is the same here as it is for the command line.