I am working on a cocos2d-x project in Lua. I have a problem with syntax openien file, when I invoke:
cocos2d.CCFileData:new("file.txt", "w"+)
I always get error:
Cocos2d: ...80-C048-4F64-BC52-4849C0AD02F5/Main.lua:30: attempt to index field 'CCFileData' (a nil value)
What am I doing wrong? i cannot get any doc info. I am doing this on iOS.
1) Are you sure the call must be prefixed with "cocos2d"? Without knowing cocos2d-x but according to the error message maybe this is the correct call?
CCFileData:new("file.txt", "w+")
2) The "w"+ is certainly incorrect. It needs to be "w+" all in quotes:
cocos2d.CCFileData:new("file.txt", "w+")
Well the CCFileData is just not implemented yet in Cocos2d-x. I have managed this by using io.open lua funcion. It helped to have Lua file routines.
Use this type of call:
xmlFilePath = CCFileUtils::fullPathFromRelativePath("NameOfFile.xml");
I just spent a decent 30 minutes looking for a working version of this. The Cocos2d author, in January, recommends using a different file which I have yet to get working, but I just tested this and I am successfully reading an XML file finally. Thought I'd share this method, since iOS usually uses
[[NSBundle mainBundle] pathForResource:#"" ofType:#""];
styles to get the paths. We have to do similar, and that's the cocos2d-x method of doing it.
Related
I created an app that works which is similar to the examples from the Marmalade SDK. Then I tried to move the IwUIController derived class in a separate files .h/.cpp to clean the code up a bit but I get a crash every time I try to access any IwUIElement? For example:
CIwUIImage* image = IwSafeCast<CIwUIImage*>(pScreen->GetChildNamed("Image"));
pScreen is declared as
static CIwUIElement *pScreen;
and then in main(): pScreen = CIwUIElement::CreateFromResource("Screen");
What can be the reason for these crashes? Does the Controller class need to be in the same file as main()? I've tried to debug and the pointer appears to be passed properly.
Not sure it really counts as an answer, but I don't have enough stackoverflow reputation to comment apparently;-)
If you've got C++ code that worked OK until you split it into two files, I would seriously check the #include and other declarations are the same in the new two files as they were in the originals. 9 times out of 10, my experience is that for some reason something is not the same. Actually one specific issue worth checking for is that a struct or class is only partly declared (e.g. a forward declaration) in one file and has lost its parent.
Having said that, as Creator, said what were the symptoms of the crash? Is this possibly the dynamic cast failing of IwSafeCast failing?
I have an OpenCL kernel that runs well but I want to look at the intermediate code. I use getprograminfo to pull out the binary and save it to a text file. I've tried this with nVidia, AMD, an i7 and a Xeon.
In all of these cases the binary is unreadable.
I understand that on OS X the chunk of data returned is actually a binary plist. I've found instructions for using plutil to convert it to xml, and they work.
It's still unreadable ... though I've seen instructions online that this is where you find the PTX code (in the case of my AMD 5870). There's the expected clBinaryData key but the data under that key is still one big chunk of stuff, not readable IL instructions in text form.
I'd really like to examine the intermediate language to assess inefficiencies in my use of the gpu. Is this simply not possible under Xcode? Or, what am I doing wrong?
Thanks for any information!...
If you run your program with following environmental variable set you should see .IL and .ISA files in your directory.
$ GPU_DUMP_DEVICE_KERNEL=3 ./my-program
Another way is to use AMD APP Kernel Analyzer (which comes along with AMD APP SDK) to look at the Intermediate file i.e IL and ISA.
(I am not sure whether AMD APP SDK available for MAC or not).
One more option according to APP SDK documentation, put the below in your host code.
putenv("GPU_DUMP_DEVICE_KERNEL=3");
References
AMD OpenCL Programming Guide
AMD Devgurus forum
(Making this a top-level answer so I can do some formatting.)
ocluser's answer was very helpful, in that it was enlightening and caused great learning, though it did not, alas, solve the problem.
I've verified that the environment variable described is being set, and is available to my application when run from within xcode. However, it does not have (under OSX) the highly desirable effect it has under Linux.
But, I now know how to set environment variables in 7 of 8 different ways. I also set "tracer" envars to tell me which methods are effective within the scope of my application. From the below, you can see that both the method of "edit scheme" to add arguments works, as does the "putenv" suggested by ocluser. What didn't set it in that scope: ~/.MACOS/environment.plist, app-specific plist, .profile, and adding a build phase to run a custom script (I found at least one other way within xcode to set one but forgot what I called the tracer and can't find it now; maybe it's on another machine....)
GPU_DUMP_DEVICE_KERNEL is 3
GPU_DUMP_TRK_ENVPLIST is (null)
GPU_DUMP_TRK_APPPLIST is (null)
GPU_DUMP_TRK_DOTPROFILE is (null)
GPU_DUMP_TRK_RUNSCRIPT is (null)
GPU_DUMP_TRK_SCHARGS is 1
GPU_DUMP_TRK_PUTENV is 1
... so, no this doesn't really answer the question, but expands on it a bit. Sorry if poor form. Thanks!
Have not given up and shall provide an actual problem-solver if I find one.
I just installed the cocos2d templates in Xcode 4. When I create a new project from the template and run it, it shows around 30 compiler errors. Even without making any changes to the template. Do you have any idea what is wrong?
Please add some more information about errors, but it looks like you forgot to add to your project OpenGLES and QuartzCore frameworks. I could be wrong...
I just spent 10 or 15 minutes plus fixing a bunch of errors in this situation, so i will guess: moving to Xcode 4.X caused many problems for cocos2d projects (including Kobold2D) and most of them require putting "(unsigned int)" in front of an argument in a list of arguments to a 'string with format' type operation creating mostly debug type output. usually the argument in question is "self", but sometimes just other "types" that resolve to (or can) unsigned ints. in a few cases I had no arguments but a reference to the error string to %#; these required adding a ", self" between the end of string and the close paren. in about 5 to 10% of cases, "fixits" were provided to automate the correction (usually changing the format character to match the argument). Hope this helps! Happy to provide examples if this actually helps anyone.
I'm trying to use smarttabs.el from https://gist.github.com/188961 in latest emacs-dev (bzr). When trying to compile or load it I get the error:
smarttabs.el:54:1:Error: Don't know how to make a localized variable an alias
which is completely new to me. How do I correct this?
Also see http://www.emacswiki.org/emacs/SmartTabs for package explanation.
The error message is trying to say that defvaralias (used in the smart-tabs-advice macro) doesn't do what jacius thinks it does. But I'm not quite sure what he thinks it does, so I'm not sure how to fix it. Try reporting the error to him.
I'm writing an iPhone app that is mainly centered around grid patterns, so I have a Pattern class which contains an NSMutableArray of NSMutableArrays. This class implements NSCoding, and it seems the following code works just fine in my iPhone app:
GridPattern * pattern = [GridPattern patternWithWidth:8 height:8];
[pattern setValueAtColumn:0 row:7 value:1];
[NSKeyedArchiver archiveRootObject:pattern toFile:#"test.pat"];
pattern = [NSKeyedUnarchiver unarchiveObjectWithFile:#"test.pat"];
If I debug the code above, I find after stepping over line 4, that I have a GridPattern object with the appropriate value set for column 0, row 7.
I have also written a Cocoa OSX application intended for creating patterns for the iPhone app, which also uses the same GridPattern class. It can also load and save the patterns successfully.
What I wanted to do was:
create and save the patterns in the OS X app
add the pattern files into Resources group in XCode for the iPhone app; (I added it as test.pat)
unarchive the patterns in my iPhone app, using code such as:
pattern = [NSKeyedUnarchiver unarchiveObjectWithFile:#"test.pat"];
However, when I try to unarchive the objects from this file, all that is returned is nil. I thought I might have had the file path wrong and also tried #"Resources/test.pat" to no avail.
Am I simply referring to the file incorrectly? Or are archived objects simply not cross-platform? Is this whole approach just plain wrong? If so, how would you do it?
I don't know about the compatibility of archiving across platforms, but to refer to a bundle resource, you should always use NSBundle to find it. Don't depend on the current path.
As your model is just an array of arrays, you could use XML property lists which do work across architectures.