質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
openFrameworks

openFrameworksは、C++で記述されたライブラリ群です。既存のライブラリの設定なしで使用できるため「糊」のようなツールキットと呼ばれています。簡単なコードだけで様々なグラフィックスやインタラクションをデザインすることが可能です。

Q&A

0回答

1077閲覧

openFrameworksのエラー(Thread 1: EXC_BAD_ACCESS (code=1, address=0x50))の直し方

NazunaM

総合スコア0

openFrameworks

openFrameworksは、C++で記述されたライブラリ群です。既存のライブラリの設定なしで使用できるため「糊」のようなツールキットと呼ばれています。簡単なコードだけで様々なグラフィックスやインタラクションをデザインすることが可能です。

0グッド

0クリップ

投稿2021/04/23 05:25

前提・実現したいこと

現在、
「Beyond Interaction[改訂第3版] クリエイティブ・コーディングのためのopenFrameworks実践」
という書籍を使ってopenFrameworksを学習しています。
アドオンの追加のチャプターで、ofxBox2dとofxOpenCvを組み合わせたプログラムの作成の部分に取り組んでいます。

以下に書くコードを模写して実行し、「buid Succeeded」と表示されるものの、エラーが発生してうまく実行されません。
この解決方法を知りたいです。

openFrameworksを勉強し始めたばかりの初心者で、プログラミングのことについてわからないことばかりです。
初歩的なことだと本当に申し訳ないのですが、どなたかエラーの治し方を教えていただければと思います。

発生している問題・エラーメッセージ

(赤いライン状に出ているメッセージ)

Thread 1: EXC_BAD_ACCESS (code=1, address=0x50)
2021-04-23 14:11:19.365504+0900 myGoodSketch_2Debug[5024:151632] [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x60000243e920> 30010C1C-93BF-11D8-8B5B-000A95AF9C6A 2021-04-23 14:11:19.382098+0900 myGoodSketch_2Debug[5024:151632] [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x60000241c1a0> F8BB1C28-BAE8-11D6-9C31-00039315CD46 [warning] ofAvFoundationGrabber: requested width and height aren't supported. Setting capture size to closest match: 640 by 480 2021-04-23 14:11:19.442327+0900 myGoodSketch_2Debug[5024:151632] [] CMIOHardware.cpp:379:CMIOObjectGetPropertyData Error: 2003332927, failed [notice ] ofxBox2d:: - world created - [notice ] particleIterations 1 [notice ] particleIterations 1 2021-04-23 14:11:21.154379+0900 myGoodSketch_2Debug[5024:151724] Metal API Validation Enabled [notice ] ofxCvColorImage: setFromPixels(): reallocating to match dimensions: 320 240 [ error ] ofxCvGrayscaleImage: operator=: region of interest mismatch (lldb)

該当のソースコード

以下のコードは実際に実行しようとしたコードです。
[ofApp.cpp]

#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup(){ ofBackground(0,0,0); ofSetFrameRate(60); vidGrabber.initGrabber(320, 240); colorImg.allocate(320, 240); grayImage.allocate(320, 240); grayBg.allocate(320, 240); grayDiff.allocate(320, 240); bLearnBakground = true; threshold = 100; box2d.init(); box2d.setGravity(0, 1); box2d.createBounds(0, 0, colorImg.width, colorImg.height); box2d.setFPS(30); box2d.checkBounds(true); static const int NUM = 1000; for (int i=0; i < NUM; i++){ auto circle = make_shared<CustomCircle>(); circle->setPhysics(1.0, 0.8, 0.0); circle->setup(box2d.getWorld(), ofRandom(colorImg.width), ofRandom(colorImg.height), 3); circles.push_back(circle); } } //-------------------------------------------------------------- void ofApp::update(){ box2d.update(); bool nNewFrame = false; vidGrabber.update(); nNewFrame = vidGrabber.isFrameNew(); if(nNewFrame){ colorImg.setFromPixels(vidGrabber.getPixels()); grayImage = colorImg; if (bLearnBakground == true) { grayBg = grayImage; bLearnBakground = false; } grayDiff.absDiff(grayBg, grayImage); grayDiff.threshold(threshold); contourFinder.findContours(grayDiff, 20, (340 * 240) / 3, 10, false); for (int i=0; i < contourCircles.size(); i++){ contourCircles[i]->destroy(); } contourCircles.clear(); for(int i=0; i < contourFinder.blobs[i].pts.size(); i += 4){ for(int j=0; j < contourFinder.blobs[i].pts.size(); j += 4){ glm::vec2 pos = contourFinder.blobs[i].pts[j]; auto circle = make_shared<ofxBox2dCircle>(); circle->setup(box2d.getWorld(), pos.x, pos.y, 4); contourCircles.push_back(circle); } } } }

[ofApp.h]

#pragma once #include "ofMain.h" #include "ofxBox2d.h" #include "ofxOpenCv.h" #include "CustomCircle.h" class ofApp : public ofBaseApp{ public: void setup(); void update(); void draw(); void keyPressed(int key); void keyReleased(int key); void mouseMoved(int x, int y ); void mouseDragged(int x, int y, int button); void mousePressed(int x, int y, int button); void mouseReleased(int x, int y, int button); void mouseEntered(int x, int y); void mouseExited(int x, int y); void windowResized(int w, int h); void dragEvent(ofDragInfo dragInfo); void gotMessage(ofMessage msg); ofxBox2d box2d; vector <shared_ptr<CustomCircle> > circles; vector <shared_ptr<ofxBox2dCircle> > contourCircles; ofVideoGrabber vidGrabber; ofxCvColorImage colorImg; ofxCvGrayscaleImage grayImage; ofxCvGrayscaleImage grayBg; ofxCvGrayscaleImage grayDiff; ofxCvContourFinder contourFinder; bool bLearnBakground; int threshold; };

[CustomCircle.cpp]

#include "CustomCircle.h" void CustomCircle::draw(){ float radius = getRadius(); ofPushMatrix(); ofTranslate(getPosition().x, getPosition().y); ofFill(); ofSetColor(31, 127, 255, 100); ofDrawCircle(0,0, radius); ofSetColor(31, 127, 255, 200); ofDrawCircle(0,0, radius * 0.7); ofPopMatrix(); }

[CustomCircle.h]

#ifndef CustomCircle_h #define CustomCircle_h #include <stdio.h> #endif /* CustomCircle_hpp */ #pragma once #include "ofMain.h" #include "ofxBox2d.h" class CustomCircle : public ofxBox2dCircle { public: void draw(); };

以下のコードはエラーが出ていた部分です。endの部分に赤い下線が引かれていました。

_LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT {return static_cast<size_type>(this->__end_ - this->__begin_);} _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT {return __base::capacity();} _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return this->__begin_ == this->__end_;} size_type max_size() const _NOEXCEPT; void reserve(size_type __n); void shrink_to_fit() _NOEXCEPT;

試したこと

サイト
https://www.bhnt.co.jp/blog/%E9%9B%91%E8%A8%98/%E7%A4%BE%E5%93%A1%EF%BC%9Acobra/xcode-exc_bad_access%E3%82%82%E6%80%96%E3%81%8F%E3%81%AA%E3%81%84%EF%BC%81%E5%8E%9F%E5%9B%A0%E3%82%92%E7%89%B9%E5%AE%9A%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95%E3%80%82/)
を参考にし、All Exceptionsを追加しました。

そのあと実行した際に、theread breakpoint1.2などといったメッセージが出てきたので、「deleat breakpoint」をしました。
しかし、その後も立て続けに同じようなエラーメッセージが出てきます。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問