change to unique ptr still works -> but i beleive we have a memory leak now.
This commit is contained in:
parent
383186a102
commit
f5b962f65b
@ -23,7 +23,7 @@ NMainWindow* QMainWindowWrap::getInternalInstance() {
|
||||
QMainWindowWrap::QMainWindowWrap(const Napi::CallbackInfo& info): Napi::ObjectWrap<QMainWindowWrap>(info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
SuppressDestruct();
|
||||
// SuppressDestruct();
|
||||
|
||||
if(info.Length() == 1) {
|
||||
Napi::Object parentObject = info[0].As<Napi::Object>();
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
class NPushButton: public QPushButton, public YogaWidget
|
||||
{
|
||||
private:
|
||||
std::shared_ptr<ThreadSafeCallback> emitRef;
|
||||
std::unique_ptr<ThreadSafeCallback> emitRef;
|
||||
public:
|
||||
SET_YOGA_WIDGET_Q_PROPERTIES
|
||||
using QPushButton::QPushButton; //inherit all constructors of QPushButton
|
||||
@ -19,25 +19,25 @@ public:
|
||||
handleButton()
|
||||
));
|
||||
}
|
||||
~NPushButton(){
|
||||
spdlog::info("DESTRUCTOR CALLED NPUSHBUTTON");
|
||||
this->emitRef.reset();
|
||||
}
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void handleButton(){
|
||||
emitRef->call([](Napi::Env env, std::vector<napi_value>& args)
|
||||
emitRef->call([](Napi::Env env, std::vector<napi_value>& args)
|
||||
{
|
||||
// This will run in main thread and needs to construct the
|
||||
// arguments for the call
|
||||
args = { Napi::String::New(env, "clicked"), Napi::String::New(env, "YOLO") };
|
||||
});
|
||||
spdlog::info("HANDLEBUTTON CALLED NPUSHBUTTON");
|
||||
spdlog::info("HANDLEBUTTON CALLED NPUSHBUTTON");
|
||||
|
||||
}
|
||||
public:
|
||||
void setNodeEmitterEmit(std::shared_ptr<ThreadSafeCallback> emitterEmit){
|
||||
this->emitRef = emitterEmit;
|
||||
}
|
||||
~NPushButton(){
|
||||
spdlog::info("DESTRUCTOR CALLED NPUSHBUTTON");
|
||||
this->emitRef.reset();
|
||||
void setNodeEmitterEmit( std::unique_ptr<ThreadSafeCallback> &emitterEmit){
|
||||
this->emitRef = std::move(emitterEmit);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -20,9 +20,9 @@ class QPushButtonWrap : public Napi::ObjectWrap<QPushButtonWrap> {
|
||||
|
||||
Napi::Value setNodeEventEmiiter(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
std::shared_ptr<ThreadSafeCallback> emitterEmit = std::make_shared<ThreadSafeCallback>(info[0].As<Napi::Function>());
|
||||
std::unique_ptr<ThreadSafeCallback> emitterEmit = std::make_unique<ThreadSafeCallback>(info[0].As<Napi::Function>());
|
||||
this->instance->setNodeEmitterEmit(emitterEmit);
|
||||
emitterEmit.reset();
|
||||
emitterEmit.release();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user