I need to create ID2D1DCRenderTarget, because I need compability with GDI. I do it with the following code:
ID2D1Factory* factory;
ID2D1DCRenderTarget* target;
ID2D1SolidColorBrush* brush;
using namespace D2D1;
D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &factory);
D2D1_RENDER_TARGET_PROPERTIES rtp = RenderTargetProperties();
rtp.usage = D2D1_RENDER_TARGET_USAGE_GDI_COMPATIBLE;
factory->CreateDCRenderTarget(&rtp, &target);
target->CreateSolidColorBrush(ColorF(ColorF::White), &brush);
Program crashes in the last line. But when I try to similarily create ID2D1HwndRenderTarget everything works fine. Could anyone help me?
As I checked it, it appears that problem is with RenderTargetProperties(), beacuse if D2D1_RENDER_TARGET_PROPERTIES is filled for example like that:
D2D1_RENDER_TARGET_PROPERTIES rtp = D2D1::RenderTargetProperties(
D2D1_RENDER_TARGET_TYPE_DEFAULT,
D2D1::PixelFormat(
DXGI_FORMAT_B8G8R8A8_UNORM,
D2D1_ALPHA_MODE_IGNORE),
0,
0,
D2D1_RENDER_TARGET_USAGE_NONE,
D2D1_FEATURE_LEVEL_DEFAULT
);
everything works.
Related
I'm trying to implement free drawing in my windows 8 app but I keep getting this error:
"0x800a01bd - JavaScript runtime error: Object doesn't support this action
File: fabric.js, Line: 12857, Column: 7"
Adding images to the canvas etc. all works as it does in the demos but in VS when I hovered over "fabric" in this code, fabric.Shadow is not shown as an option in the list:
setShadow: function(options) {
return this.set('shadow', new fabric.Shadow(options));
},
Does anyone know why this isn't working for me? I created a build of the api from www.fabricjs.com and included all modules. I've copied the code from the free drawing demo (http://fabricjs.com/freedrawing/) but no joy. I also tried removing any reference to creating a shadow as I don't plan on using that functionality but it still crashes. Thank you
Thank you! It's working for me now. I did have to change the JavaScript provided by the demo to make it work though. Just as a reference to anyone who may want to use it with Windows 8 in future, the jquery code needs to be made more strict for it to update the selectors.
Provided code:
var $ = function(id){return document.getElementById(id)};
var drawingModeEl = $('drawing-mode'),
drawingOptionsEl = $('drawing-mode-options'),
drawingColorEl = $('drawing-color'),
drawingShadowColorEl = $('drawing-shadow-color'),
drawingLineWidthEl = $('drawing-line-width'),
drawingShadowWidth = $('drawing-shadow-width'),
drawingShadowOffset = $('drawing-shadow-offset'),
clearEl = $('clear-canvas');
I did away with the above and just used the standard jquery selector $('#drawing-mode') each time I needed it. Then the events were provided as:
drawingModeEl.onclick = function() {}
drawingColorEl.onchange = function() {}
so I changed the above to:
$('#drawing-mode').on('click', function () {});
$('#drawing-color').change(function (){});
Now everything works as it does in the demo. Love this API, thank you!
I'm stuck with this problem and simply cannot get it solved, sorry if there was another post about this already but I couldn't find it as well.
On to the problem then: I'm trying to make a simple function capable of initializing and updating bitmaps, and a few other variables I haven't thought of yet, when needed.
I created on the stage some MovieClips called slot0, slot1, slot2 etc... inside another MovieClip called ButtonRootPannel in order to have a visual of where I'll be putting the images without having to guess numbers in the code.
Together with those I set up this code:
var buttons_rootArray:Array = new Array;
for(var i=0;i<=11;i++){
this["slot"+i] = this.ButtonRootPannel.createEmptyMovieClip("slot"+i, i);
this["slot"+i].customState = "Inactive"; //Active, Inactive or Unavaiable
this["slot"+i]._x = eval("_root.ButtonRootPannel.slot"+i)._x;
this["slot"+i]._y = eval("_root.ButtonRootPannel.slot"+i)._y;
this["slot"+i]._width = eval("_root.ButtonRootPannel.slot"+i)._width;
this["slot"+i]._height = eval("_root.ButtonRootPannel.slot"+i)._height;
buttons_rootArray.push(this["slot"+i]);
}
UpdateButtonsSlot(0,"BuildButton");
UpdateButtonsSlot(1,"CancelButton");
function UpdateButtonsSlot(slot:Number, newImage:String):Void{
var tempData:BitmapData = BitmapData.loadBitmap(newImage);
var tempClip:MovieClip = eval(buttons_rootArray[slot]);
//buttons_rootArray[slot].unloadMovie();
//buttons_rootArray[slot].clear();
tempClip.attachBitmap(tempData,this.getNextHighestDepth(),"auto",true);
}
Anyone knows what I might be doing wrong?
Thanks in advance.
Well, problem solved, this now seems to be working for some strange reason:
for(var i=0;i<=11;i++){
var currentMC = eval("_root.ButtonRootPannel.slot"+i);
this["slot"+i] = this.ButtonRootPannel.createEmptyMovieClip("slot"+i, i);
this["slot"+i].customState = "Inactive"; //Active, Inactive or Unavaiable
this["slot"+i]._x = currentMC._x;
this["slot"+i]._y = currentMC._y;
//this["slot"+i]._width = currentMC._width;
//this["slot"+i]._height = currentMC._height;
buttons_rootArray.push(this["slot"+i]);
}
Only those commented lines makes the MovieClip disappear if I uncomment them. Will just leave them out then and problem solved.
Having some seriously frustrating issues with my latest app!!
I'm using OpenGLES 1 to draw models to the screen that are constantly updating, then you can take a screenshot and share however you like, after that you can return to the app start screen and start again.
All seems to work fine the first time the app runs through, no crashes. But if you run through it once then try to go through again, as soon as the OpenGLES drawing view has to start drawing the elements, it throws up an EXC_BAD_ACCESS error on my glDrawElements line.
I given up on trying to fix this error for now, I've had no luck in the last 2 weeks!!
I have set the property in my plist so that the app doesn't run in the background, and whenever I run it through once, then exit it and load it up again it will run through again absolutely fine.
So what I was wondering is if I could somehow emulate the functionality of the exit(0) feature, but without actually exiting from the app?
So in essence, each time the user navigates from the sharing page back to the home page, the app would run the exit code, leaving the app to run from scratch again.
This would, in my head at least, not be a great way at all of dealing with the situation, but I need results quick and this seems like a good way out for now until I can get to the bottom of the actual error.
Thanks,
Matt
EDIT 1: I'm not looking to put the app on the store with this fix in place, it is just a temporary thing.
EDIT 2: Posted code containing my draw functionality, taken and adapted from Bill Dudney's WaveFront .obj loader
for(WaveFrontOBJGroup *group in scene.groups)
{
NSString *matPath = [NSString stringWithFormat:#"%#%#.mtl", materialName, modelPart];
NSArray *materialArray = [WaveFrontOBJMaterial materialsFromLibraryFile:matPath];
WaveFrontOBJMaterial *mat = [materialArray objectAtIndex:0];
if(group.smoothing)
glShadeModel(GL_SMOOTH);
else
glShadeModel(GL_FLAT);
// load (if necessary) and bind the vertices
GLuint verticesName = [group verticesName:GL_STATIC_DRAW];
glBindBuffer(GL_ARRAY_BUFFER, verticesName);
glVertexPointer(3, GL_FLOAT, 0, 0);
// load (if necessary) and bind the normals
GLuint normalsName = [group normalsName:GL_STATIC_DRAW];
glBindBuffer(GL_ARRAY_BUFFER, normalsName);
glNormalPointer(GL_FLOAT, 0, 0);
ColorRGBA color = mat.ambientColor;
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (GLfloat *)&color);
color = mat.diffuseColor;
if(alpha)
glColor4f(color.red, color.green, color.blue, mat.disolve);
else
glColor4f(color.red, color.green, color.blue, color.alpha);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (GLfloat *)&color);
color = mat.specularColor;
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (GLfloat *)&color);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, mat.shine);
// load (if necessary) and bind the texture
if(group.textureCoordinatesIndexData.length > 0)
{
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
GLuint textureCoordsName = [group textureCoordinatesName:GL_STATIC_DRAW];
glEnable(GL_TEXTURE_2D);
glBindBuffer(GL_ARRAY_BUFFER, textureCoordsName);
glTexCoordPointer([group texCoordSize], GL_FLOAT, 0, 0);
GLuint texId = [mat.diffuseTexture textureName];
glBindTexture(GL_TEXTURE_2D, texId);
}
GLuint indexesName = [group indexesName:GL_STATIC_DRAW];
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexesName);
glDrawElements(GL_TRIANGLES, group.indexCount, GL_UNSIGNED_SHORT, NULL);
//^^This line above is where I get the "EXC_BAD_ACCESS" message
if(group.textureCoordinatesIndexData.length > 0)
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
I've checked group.indexCount through breakpoints and NSLog's and it is not null, it is exactly the same as when it runs through the first time which works fine.
I realise it won't necessarily be on that line, I've heard other talk about it being due to variables not being initialised as pointers - * - or NSStrings not having matching identifiers and values (#"%# sometext %#", variable); but I don't see any of those in my code, of course I could easily be missing one.
Remember two things:
1) You have a method -(void)viewWillAppear:(BOOL)animated in your home ViewController. This will call always (!) when user return to this screen (not like viewDidLoad).
2) If you even do this like you described you probably didn't get to the AppStore!
I'm not sure why your application won't compile on the simulator, but you should try to link your libraries appropriately so that you can get that up and running - nothing is better for bad access errors than zombies.
If you know your error is from calling glDrawElements then you should look into what's being passed to it. This link might be able to help you.
The reason you can't get the "functionality" of exiting your app while still in the app is because it's not a function of the application - it's the OS throwing away everything associated with the application and then reloading it. By definition you won't be able to do this without actually shutting down.
However, if your problem is fixed by this, then it is likely that there's something in your setup that needs to be redone (initializations, declarations, etc). Check to see what's getting set to nil or thrown away and then set it back up.
Without looking at your code I can't say this with any certainty, but you may be able to write a method that overwrites/reinitializes all of your current variables. This would probably replicate the part of exiting the application that you need.
What is the equivalent to removeMovieClip() in AS3?
Apparently many have the same question:
StackOverflow:
How to completely remove a movieclip in as3
Remove movie clip as3
How to remove childmovieclip and add to new parent movieclip
Others:
removeMovieClip(this) in AS3?
Destroy/Delete a Movieclip???
Remove movie clip
But none of their solutions seem to work, for me:
Im working on flash CS4 with AS3:
I have a very simple movie with a single button called click. On pressing the button, a new instance of coin is created:
this.click.addEventListener(MouseEvent.CLICK,justclick);
function justclick(e:MouseEvent){
var money=new coin
this.addChild(money)
money.x=e.stageX
money.y=e.stageY
}
It might not be the best code, but it works fine. Now, the coin MovieClip is supposed to show a small animation and remove itself. In good old AS2 I would have added:
this.removeMovieClip()
in the last frame of the animation. But this doesn't exist in AS3.
I have tried, without success:
this.parent.removeChild(this) // 'Cannot access a property or method of nullobject reference'...
this.removeMovieClip() // 'removeMovieClip is not a function'
removeMovieClip(this) //'call to possibly undefined method removeMovieClip'
unloadMovie(this)//'call to possibly undefined method removeMovieClip'
Solutions?
Thanks,
this.parent.removeChild(this);
This one should be working; it's what I use. One problem I had when I switched to AS3 is that sometimes it wouldn't be added as a child right, so you might want to check that. You also have to import flash.display via putting this at the top if you're not already:
import flash.display.*
You should also remove the event listener on it before removing it.
If your animation is ending on frame 20.
note: using 19 because flash count frames from zero(0) similar to array index.
class animatedCloud
{
public function animatedCloud(){
addFrameScript(19, frame20);
}
private function frame20(){
parent.removeChild(this);
}
}
Always ensure that those self removing movieclips can get garbage collected.
This solution wiped away all my instances from a loaded swf's library symbol:
var mc:MovieClip = new definition() as MovieClip;
addChild(mc);
mc.x = 1000 * Math.random();
mc.y = 1000 * Math.random();
mc.addFrameScript(mc.totalFrames - 1, function onLastFrame():void
{
mc.stop();
mc.parent.removeChild(mc);
mc = null;
});
public static function removeDisplayObject(displayObject:DisplayObject):void {
/* normal code
if(displayObject && displayObject.parent){
displayObject.parent.removeChild(displayObject);
}
*/
displayObject ? displayObject.parent ? displayObject.parent.removeChild(displayObject) : null : null;
}
I use, in an extra blank keyframe at the end of the MovieClip which should remove itself:
stop();
MovieClip(parent).removeChild(this);
Found it to be the proper and best solution.
i have to run following javascript through one of my method. But its not running
Whats wrong with the code.
private void fillGrid1()
{
GridView1.DataSource = myDocCenter.GetDsWaitingForMe(Session["UserID"].ToString());
HiddenField1.Value = { myDocCenter.GetDsWaitingForMe(Session["UserID"].ToString()).Tables[0].Rows.Count).ToString();
GridView1.DataBind();
String csname1 = "PopupScript1";
String csname2 = "ButtonClickScript1";
Type cstype = this.GetType();
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
// Check to see if the client script is already registered.
if (!cs.IsClientScriptBlockRegistered(cstype, csname2))
{
StringBuilder cstext2 = new StringBuilder();
cstext2.Append("<script type=\"text/javascript\"> ");
// You can add JavaScript by using "cstext2.Append()".
cstext2.Append("var count = document.getElementById('ctl00_ContentPlaceHolder1_HiddenField2');");
cstext2.Append("var count = '100';");
cstext2.Append("document.getElementById('sp2').innerHTML = count;");
cstext2.Append("script>");
cs.RegisterClientScriptBlock(cstype, csname2, cstext2.ToString(), false);
}
}
Your script tag is not properly closed.
Change
cstext2.Append("script>");
to
cstext2.Append("</script>");
On top of what adamantium said, your JS looks a bit strange. You seem to declare and set the count variable twice - did you mean to do this.
Following that, best thing to do, render the page then view source. is your JS getting rendered to the page? try and stick an alert in there... is it firing?
> cstext2.Append("var count =
> document.getElementById('ctl00_ContentPlaceHolder1_HiddenField2');");
I would use the ClientID property here. HiddenField2.ClientID
RegisterClientScriptBlock emits the script just after the <form> tag openning. Browser executes this script just after the tag openning as well but referenced elements are not processed yet at this time - browser cannot find them.
RegisterStartupScript method emits the script just before the <form> tag ending. Nearly all page elements are processed by the browser at this place and getElementById could find something.
See http://jakub-linhart.blogspot.com/2012/03/script-registration-labyrinth-in-aspnet.html for more details.