8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

cocos2d-x 3.10 「=」演算子でSprite等の代入を行うと画面遷移時にエラーが出る

Last updated at Posted at 2016-02-16

概要

タイトルの通りですが、自分自身とってもハマったのでメモ書きとして残しておきます。

問題

Sprite等のRefクラスを継承するつクラスを=演算子で値の代入を行った結果、その変数をメンバにもつSceneを遷移させた時エラーが出てしまう。というもの

エラーの内容はこちら

Assert failed: reference count should be greater than 0
Assertion failed: (_referenceCount > 0), function release, file
/Users/UserName/Documents/CocosProjects/Project/cocos2d/cocos/base/CCRef.cpp, line 111.

エラー箇所

CCRef.cpp
//~略~
void Ref::release()
{
    CCASSERT(_referenceCount > 0, "reference count should be greater than 0");
    --_referenceCount;

#if CC_ENABLE_SCRIPT_BINDING && CC_ENABLE_GC_FOR_NATIVE_OBJECTS

//~略~

直し方

なお、_title はCC_SYNTHESIZE_RETAINのプロパティマクロによって宣言されています
こうしてたのを

auto title = Sprite::create();
_title = title; 
this->addChild(_title);

こうする。

auto title = Sprite::create();
this->setTitle(title); //変更箇所
this->addChild(_title);

まとめ

セッターを使おうっていう記事でした。

8
8
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?