cocos2d-x Sprite::create("filename.png") returning null - cocos2d-x

For some reason this stopped working. It was working last time I was working on the project, but now it's not. I have double checked that spaceCannonTitle.png is included in the project. But it's throwing an exception on the setPosition line because title_sprite is null.
bool MenuScene::init()
{
if ( !Layer::init() )
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
auto title_sprite = cocos2d::Sprite::create( "spaceCannonTitle.png" );
title_sprite->setPosition( Point( visibleSize.width / 2 + origin.x, visibleSize.height - title_sprite->getContentSize( ).height ) );
this->addChild( title_sprite );
...
}
EDIT:
If I comment out the title_sprite, then it doesn't crash, but I don't see the menu and I get this error:
libpng error: CgBI: unhandled critical chunk

I found the solution here. Apparently you have to go to Build Settings and set Remove Text Metadata From PNG Files to NO.

Related

C# - Can not access File which is already being used - Iron OCR

I am using "Iron OCR", something like "Tesseract" to detect and scan certain Text from Screenshots.
Now I have the following error. Every time Iron OCR is used to scan an image for text it tries to access the Iron OCR log file which is somehow still used by the process before. So every time I get the error message that it can't access the log file because it is already in use. Nevertheless the Scan still works and I get a valid result even tho it gives me an exception because of that error.
My program works like this:
it takes a screenshots of certain areas of my screen.
it analyzes that image with Iron OCR and looks for text.
this process repeats itself infinitely.
I have following code:
//------------------------- # Capture Screenshot of specific Area # -------------------------\\
Rectangle bounds3;
Rect rect3 = new Rect();
bounds3 = new Rectangle(rect3.Left + 198, rect3.Top + 36, rect3.Right + 75 - rect3.Left - 10, rect3.Bottom + 30 - rect3.Top - 10);
CursorPosition = new Point(Cursor.Position.X - rect.Left, Cursor.Position.Y - rect.Top);
Bitmap result3 = new Bitmap(40, 14);
using (Graphics g = Graphics.FromImage(result3))
{
g.CopyFromScreen(new Point(bounds3.Left, bounds3.Top), Point.Empty, bounds3.Size);
}
//------------------------- # Analyze Image for Text # -------------------------\\
var Ocr = new IronTesseract();
using (var Input = new OcrInput(result))
{
Input.Contrast();
Input.EnhanceResolution(300);
Input.Invert();
Input.Sharpen();
Input.ToGrayScale();
try
{
//------------------- # This causes the Error - Using Try Catch to Ignore it # -------------------\\
var Result = Ocr.Read(Input);
text = Result.Text;
}
catch
{
}
}
Also removing all the above only using their "1 Line Code" gives the same error message:
var Result = new IronTesseract().Read(#"images\image.png").Text;
I hope someone can help me to figure out what exactly causes that issue.

Equivalent of Platform::IBoxArray in C++/WinRT

I am currently porting an UWP application from C++/CX to C++/WinRT. I encountered a safe_cast<Platform::IBoxArray<byte>^>(data) where data is of type Windows::Foundation::IInspectable ^.
I know that the safe_cast is represented by the as<T> method, and I know there are functions for boxing (winrt::box_value) and unboxing (winrt::unbox_value) in WinRT/C++.
However, I need to know the equivalent of Platform::IBoxArray in order to perform the cast (QueryInterface). According to https://learn.microsoft.com/de-de/cpp/cppcx/platform-iboxarray-interface?view=vs-2017, IBoxArray is the C++/CX equivalent of Windows::Foundation::IReferenceArray, but there is no winrt::Windows::Foundation::IReferenceArray...
Update for nackground: What I am trying to achieve is retrieving the view transform attached by the HoloLens to every Media Foundation sample from its camera. My code is based on https://github.com/Microsoft/HoloLensForCV, and I got really everything working except for this last step. The problem is located around this piece of code:
static const GUID MF_EXTENSION_VIEW_TRANSFORM = {
0x4e251fa4, 0x830f, 0x4770, 0x85, 0x9a, 0x4b, 0x8d, 0x99, 0xaa, 0x80, 0x9b
};
// ...
// In the event handler, which receives const winrt::Windows::Media::Capture::Frames::MediaFrameReader& sender:
auto frame = sender.TryAcquireLatestFrame();
// ...
if (frame.Properties().HasKey(MF_EXTENSION_VIEW_TRANSFORM)) {
auto /* IInspectable */ userData = frame.Properties().Lookup(MF_EXTENSION_VIEW_TRANSFORM);
// Now I would have to do the following:
// auto userBytes = safe_cast<Platform::IBoxArray<Byte> ^>(userData)->Value;
//viewTransform = *reinterpret_cast<float4x4 *>(userBytes.Data);
}
I'm also working on porting some code from HoloLensForCV to C++/WinRT. I came up with the following solution for a very similar case (but not the exact same line of code you ask about):
auto user_data = source.Info().Properties().Lookup(c_MF_MT_USER_DATA); // type documented as 'array of bytes'
auto source_name = user_data.as<Windows::Foundation::IReferenceArray<std::uint8_t>>(); // Trial and error to get the right specialization of IReferenceArray
winrt::com_array<std::uint8_t> arr;
source_name.GetUInt8Array(arr);
winrt::hstring source_name_str{ reinterpret_cast<wchar_t*>(arr.data()) };
Specifically, you can replace the safe_cast with .as<Windows::Foundation::IReferenceArray<std::uint8_t> for a boxed array of bytes. Then, I suspect doing the same cast as me (except to float4x4* instead of wchar_t*) will work for you.
The /ZW flag is not required for my example above.
I can't believe that actually worked, but using information from https://learn.microsoft.com/de-de/windows/uwp/cpp-and-winrt-apis/interop-winrt-cx, I came up with the following solution:
Enable "Consume Windows Runtime Extension" via /ZW and use the following conversion:
auto abi = reinterpret_cast<Platform::Object ^>(winrt::get_abi(userData));
auto userBytes = safe_cast<Platform::IBoxArray<byte> ^>(abi)->Value;
viewTransform = *reinterpret_cast<float4x4 *>(userBytes->Data);
Unfortunately, the solution has the drawback of generating
warning C4447: 'main' signature found without threading model. Consider using 'int main(Platform::Array^ args)'.
But for now, I can live with it ...

I want to create search feature in as3

I wrote this code to my search feature in as3 but it is not good work
because when I click on my button module, the search results are wrong. Please look at my code when I write (123456789123). My module trace is correct and when write (1234567899) my module trace is correct again?
How can I correct this problem?
my code pic is here:
please click to see my code
Make sure your txt3 string is not empty (minimum length is 1). If the txt3 length is zero it will cause problems when you check.
You want your Check function to look something like this :
function check ( evt : MouseEvent) : void
{
trace ("txt3 length is : " + txt3.length); //# if zero you get bad output later
trace ("txt3 text is : " + txt3);
if (txt2.length < 12)
{ trace ("Please Complete Every Space"); }
if ( txt3.length > 0 && txt2.text.search(txt3) >= 0)
{
trace ("correct");
}
else
{
trace ("wrong");
if ( txt3.length < 1 ) { trace ("txt3 is empty String"); }
if ( txt2.text.search(txt3) == -1 ) { trace ("txt2 VS txt3 = match was not found"); }
}
}

understanding and using hasOwnProperty

Can someone explain to me how to assign and use hasOwnProperty. I did search the web for a decent example but somehow didnt find any even at adobe( or maybe Im to "smart" to understand what it is saying )
so what Im trying to do is to set a propertie onto a MovieClip and after that to see if it exists.
var myMC:MovieClip = new MovieClip();
myMC.hasOwnProperty( "someRandomText" );
this.addChild( myMC );
if( myMC.hasOwnProperty( "someRandomText" ) ) trace(" yes it has it ")
else trace( "nothing here" )
output: nothing here
what am I doing wrong ?
and also :) how do I null/remove it after I add it to the MC
hasOwnProperty() checks whether an object has a property of that name. Basically, it'll return true if a property has an instance name matching the string.
The reason hasOwnProperty("someRandomText") returns false in your code is simply because myMC.someRandomText does not exist. Your second line seems to try making it but that's not what the function does.
A better test would be:
if( myMC.hasOwnProperty( "width" ) ) trace(" yes it has it ");
else trace( "nothing here" );
All MovieClips have a width property so this should return true. I haven't tested it but it should work.
The definition on the AS3 Reference is pretty much the best explanation you can get.

Speech API (SAPI) floating point division by zero in C++ Builder on Windows 7

I use the following code for Text-To-Speech application controls for blind persons in C++ Builder (most likely similar example can be used in Delphi). Main form has KeyPreview property checked to enable key F11 preview to start speaking active (focused) control. The code as it is works but there are some problems. This example is in C++ Builder code but from what I've found, Delphi suffers from same problem and the solution I found is the same. If you have Delphi solution, feel free to post it, it is similar anyway.
#include <sapi.h>
#include <WTypes.h>
//---------------------------------------------------------------------------
// Speak text string (synchronous function)
//---------------------------------------------------------------------------
bool SpeakText(UnicodeString Text)
{
ISpVoice* pVoice = NULL;
if (FAILED(::CoInitialize(NULL))) return false;
Word Saved8087CW = Default8087CW; // Disable floating point division by zero exception caused by Speak
Set8087CW(0x133f);
HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);
if (SUCCEEDED(hr))
{
//pVoice->SpeakCompleteEvent()
//pVoice->SetSyncSpeakTimeout(1000);
hr = pVoice->Speak(WideString(Text).c_bstr(), SPF_DEFAULT, NULL);
pVoice->Release();
pVoice = NULL;
}
Set8087CW(Saved8087CW);
::CoUninitialize();
return true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormKeyUp(TObject *Sender, WORD &Key, TShiftState Shift)
{
UnicodeString Speaker;
if (Key == VK_F11)
{
if (Screen->ActiveControl->InheritsFrom(__classid(TButton))) { Speaker += "Button, " + static_cast<TButton*>(Screen->ActiveControl)->Caption + "."; }
else if (Screen->ActiveControl->InheritsFrom(__classid(TEdit))) { Speaker += "Edit box, " + static_cast<TEdit*>(Screen->ActiveControl)->Text + "."; }
}
if (Speaker != "") SpeakText(Speaker);
}
//---------------------------------------------------------------------------
Problems:
pVoice->Speak causes Floating point division by zero if I don't override the exception using the Set8087CW function. This happens only on Windows 7 (possibly Vista and Windows 8 too) but not on Windows XP in the same program (compiled exe). Is there a solution without using Set8087CW? Removing these lines will cause the problem and exception. I have BCB2010.
Function is synchronous and won't shut up or return control to program until it finishes reading text. This is a problem for longer text. It also blocks program events. Is there a way to make it asynchronous or introduce an event to periodically check for F11 key status and if F11 is pressed again it stops reading and uninitializes object? For example poll every 300 ms (or after each word etc.) for key-press F11 and if pressed, stop speaking? Or run it threaded?
Does SAPI has memory leaks as some write on various sites?
Can above code use OleCheck instead of CoCreateInstance and CoUninitialize?
UPDATE for those looking for solution as suggested by Remy Lebeau:
SavedCW = Get8087CW();
Set8087CW(SavedCW | 0x4);
hr = pVoice->Speak(WideString(Text).c_bstr(), SPF_DEFAULT | SPF_ASYNC, NULL);
pVoice->WaitUntilDone(-1); // Waits until text is done... if F11 is pressed simply go out of scope and speech will stop
Set8087CW(SavedCW);
Also found detailed example in CodeRage 4 session: http://cc.embarcadero.com/item/27264
The error does occur in Vista as well. Masking floating point exceptions is the only solution.
To make Speak() run asynchronously, you need to include the SPF_ASYNC flag when calling it. If you need to detect when asynchronous speaking is finished, you can use ISpVoice::WaitUntilDone(), or call ISpVoice::SpeakCompleteEvent() and pass the returned HANDLE to one of the WaitFor...() family of functions, like WaitForSingleObject().
What kind of leaks do other sites talk about?
Not instead of, no. OleCheck() merely checks the value of an HRESULT value and throws an exception if it is an error value. You still have to call COM functions that return the actual HRESULT values in the first place. If anything, OleCheck() would be a replacement for SUCCEEDED() instead.
For what you are attempting, I would suggest the following approach instead:
struct s8087CW
{
Word Saved8087CW;
s8087CW(Word NewCW)
{
Saved8087CW = Default8087CW;
Set8087CW(NewCW);
// alternatively, the VCL documentation says to use SetExceptionMask() instead of Set8087CW() directly...
}
~s8087CW()
{
Set8087CW(Saved8087CW);
}
};
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent *Owner)
: TForm(Owner)
{
::CoInitialize(NULL);
}
//---------------------------------------------------------------------------
__fastcall TForm1::~TForm1()
{
if (pVoice) pVoice->Release();
::CoUninitialize();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormKeyUp(TObject *Sender, WORD &Key, TShiftState Shift)
{
if (Key == VK_F11)
{
TWinControl *Ctrl = Screen->ActiveControl;
if (Ctrl)
{
TButton *btn;
TEdit *edit;
if ((btn = dynamic_cast<TButton*>(Ctrl)) != NULL)
SpeakText("Button, " + btn->Caption);
else if ((edit = dynamic_cast<TEdit*>(Ctrl)) != NULL)
SpeakText("Edit box, " + edit->Text);
}
}
}
//---------------------------------------------------------------------------
ISpVoice* pVoice = NULL;
bool __fastcall TForm1::SpeakText(const String &Text)
{
s8087CW cw(0x133f);
if (!pVoice)
{
if (FAILED(CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice)))
return false;
}
SPVOICESTATUS stat;
pVoice->GetStatus(&stat, NULL);
while (stat.dwRunningState == SPRS_IS_SPEAKING)
{
ULONG skipped;
pVoice->Skip(L"SENTENCE", 1000, &skipped);
pVoice->GetStatus(&stat, NULL);
}
return SUCCEEDED(pVoice->Speak(WideString(Text).c_bstr(), SPF_ASYNC, NULL));
}