ã¯ããã«
åã®èšäºã§ããœãŒã¹ããOpenSceneGraphã¢ã»ã³ããªãèŠãŠã空ã®çŽ«è²ã®äžçã«ç°è²ã®å¹³é¢ãã¶ãäžãã£ãŠããåºæ¬çãªäŸãæžããã ç§ã¯åæããŸãããããŸãå°è±¡çã§ã¯ãããŸããã ãã ããåè¿°ããããã«ããã®å°ããªäŸã§ã¯ããã®ã°ã©ãã£ãã¯ãšã³ãžã³ã®ããŒã¹ãšãªãäž»èŠãªæŠå¿µããããŸãã ãããããã詳现ã«æ€èšããŸãããã 以äžã®è³æã§ã¯ãAlexander Bobkovã®OSGã«é¢ããããã°ã®ã€ã©ã¹ãã䜿çšããŠããŸãïŒèè ãOSGã«é¢ããèšè¿°ãæŸæ£ããã®ã¯æ®å¿µã§ãïŒã ãã®èšäºã¯ã OpenSceneGraph 3.0ã®è³æãšäŸã«ãåºã¥ããŠããŸãã åå¿è åãã¬ã€ã
åã®åºçç©ã¯æ¹å€ãåããŠãããšèšããããåŸãŸããããããã«ã¯éšåçã«åæããŸã-è³æã¯èšãããã«åºãŠããŠãæèããå€ããŸããã ã«ããã®äžã§ãã®çç¥ãä¿®æ£ããããšããŸãã
1.ã·ãŒã³ãšãã®ããŒãã®ã°ã©ãã«ã€ããŠç°¡åã«èª¬æããŸã
ãšã³ãžã³ã®äžå¿æŠå¿µã¯ãããããã·ãŒã³ã°ã©ãã§ã ïŒãã¬ãŒã ã¯ãŒã¯èªäœã®ååã«ãã ãã£ãã®ã¯å¶ç¶ã§ã¯ãããŸããïŒ-3次å ã·ãŒã³ã®è«ççããã³ç©ºéçè¡šçŸãæŽçã§ããéå±€ããªãŒæ§é ã§ãã ã·ãŒã³ã°ã©ãã«ã¯ãã«ãŒãããŒããšãé¢é£ããäžéããŒããšã¿ãŒããã«ããŒããŸãã¯ããŒããå«ãŸããŸãã
äŸãã°
ãã®ã°ã©ãã¯ã家ãšãã®äžã®ããŒãã«ã§æ§æãããã·ãŒã³ã瀺ããŠããŸãã 家ã«ã¯ç¹å®ã®å¹ŸäœåŠçè¡šçŸããããã«ãŒãããŒãïŒã«ãŒãïŒã«é¢é£ä»ããããç¹å®ã®åºæ¬åº§æšç³»ã«å¯ŸããŠç©ºéå ã®ç¹å®ã®æ¹æ³ã§é 眮ãããŸãã ããŒãã«ã¯ã家ã«é¢é£ããŠäœããã®æ¹æ³ã§é 眮ãããã«ãŒãããŒãã«é¢é£ããŠå®¶ãšãšãã«é 眮ããããžãªã¡ããªã«ãã£ãŠãèšè¿°ãããŸãã 1ã€ã®osg :: Nodeã¯ã©ã¹ããç¶æ¿ãããããå ±éã®ããããã£ãæã€ãã¹ãŠã®ããŒãã¯ãæ©èœçãªç®çã«å¿ããŠã¿ã€ãã«åå²ãããŸãã
- ã°ã«ãŒãããŒãïŒosg :: GroupïŒ-ãã¹ãŠã®äžéããŒãã®åºæ¬ã¯ã©ã¹ã§ãããä»ã®ããŒããã°ã«ãŒãã«çµåããããã«èšèšãããŠããŸã
- å€æããŒãïŒosg ::å€æãšãã®åå«ïŒ-ãªããžã§ã¯ã座æšã®å€æãèšè¿°ããããã«èšèšãããŠããŸã
- ãžãªã¡ããªãã¯ããŒãïŒosg :: GeodeïŒ-1ã€ä»¥äžã®ãžãªã¡ããªãã¯ãªããžã§ã¯ãã«é¢ããæ å ±ãå«ãã·ãŒã³ã°ã©ãã®ã¿ãŒããã«ïŒãªãŒãïŒããŒãã
OSGã®ã·ãŒã³ãªããžã§ã¯ãã®ãžãªã¡ããªã¯ããªããžã§ã¯ãã®ç¬èªã®ããŒã«ã«åº§æšç³»ã§èšè¿°ãããŸãã ãã®ãªããžã§ã¯ããšã«ãŒãããŒãã®éã«ããå€æããŒãã¯ããããªãã¯ã¹åº§æšå€æãå®è£ ããŠãããŒã¹åº§æšç³»ã§ã®ãªããžã§ã¯ãã®äœçœ®ãååŸããŸãã
ããŒãã¯å€ãã®éèŠãªæ©èœãå®è¡ããŸããç¹ã«ããªããžã§ã¯ãã®è¡šç€ºç¶æ ãä¿åããŸãããã®ç¶æ ã¯ããã®ããŒãã«é¢é£ä»ãããããµãã°ã©ãã®ã¿ã«åœ±é¿ããŸãã ã·ãŒã³ã°ã©ãå ã®ããŒããããŒãã®ç¶æ ãå€æŽã§ããã€ãã³ããã³ãã©ãŒãããã³ããŒââãã«é¢é£ä»ãããããµãã°ã©ãã«ãããã€ãã®ã³ãŒã«ããã¯ãé¢é£ä»ããããšãã§ããŸãã
ç»é¢äžã®æçµçµæã®ååŸã«é¢é£ããã·ãŒã³ã°ã©ãäžã®ãã¹ãŠã®ã°ããŒãã«æäœã¯ãã°ã©ããå®æçã«è©³çŽ°ã«èµ°æ»ããããšã«ããããšã³ãžã³ã«ãã£ãŠèªåçã«å®è¡ãããŸãã
ååæ€èšããäŸã§ã¯ãã·ãŒã³ã¯åäžã®ãªããžã§ã¯ããã€ãŸããã¡ã€ã«ããããŒããããé£è¡æ©ã¢ãã«ã§æ§æãããŠããŸããã ã¯ããå ãèŠããšããã®ã¢ãã«ã¯ã·ãŒã³ã°ã©ãã®ãªãŒãããŒãã§ãããšèšããŸãã ãšã³ãžã³ã®ã°ããŒãã«ãªããŒã¹åº§æšç³»ã«ãã£ãããšæº¶æ¥ãããŠããŸãã
2. OSGã¡ã¢ãªç®¡ç
ã·ãŒã³ã°ã©ãã®ããŒãã«ã¯ãã·ãŒã³ãªããžã§ã¯ããšãã®æäœã«é¢ããå€ãã®ããŒã¿ãæ ŒçŽãããããããã®ããŒã¿ãæ ŒçŽããã«ã¯ãåçã«å«ãã¡ã¢ãªãå²ãåœãŠãå¿ èŠããããŸãã ãã®å Žåãã·ãŒã³ã°ã©ããæäœãããšããããšãã°ããŒãã®äžéšãåé€ãããšããã°ã©ãã®åé€ãããããŒããåŠçãããªããªã£ãããšã泚ææ·±ãç£èŠããå¿ èŠããããŸãã éçºè ããªããžã§ã¯ããžã®ãã€ã³ã¿ãæ¢åã®ããŒã¿ãåç §ããåé€ããå¿ èŠããããã远跡ããããšã¯éåžžã«å°é£ã§ããããããã®ããã»ã¹ã«ã¯åžžã«æéã®ããããããã°ãšã©ãŒã䌎ããŸãã å¹æçãªã¡ã¢ãªç®¡çããªããã°ãã»ã°ã¡ã³ããŒã·ã§ã³ãšã©ãŒãšã¡ã¢ãªãªãŒã¯ãçºçããå¯èœæ§ãé«ããªããŸãã
ã¡ã¢ãªç®¡çã¯OSGã®éèŠãªã¿ã¹ã¯ã§ããããã®ã³ã³ã»ããã¯2ã€ã®ãã€ã³ãã«åºã¥ããŠããŸãã
- ã¡ã¢ãªã®å²ãåœãŠïŒãªããžã§ã¯ããæ ŒçŽããããã«å¿
èŠãªã¡ã¢ãªéã®å²ãåœãŠã確ä¿ããŸãã
- ã¡ã¢ãªãŒã解æŸããŸãïŒäžèŠãªå Žåã¯ãå²ãåœãŠãããã¡ã¢ãªãŒãã·ã¹ãã ã«æ»ããŸãã
CïŒãJavaãVisual Basic .Netãªã©ã®å€ãã®ææ°ã®ããã°ã©ãã³ã°èšèªã¯ãããããã¬ããŒãžã³ã¬ã¯ã¿ãŒã䜿çšããŠãå²ãåœãŠãããã¡ã¢ãªã解æŸããŸãã C ++èšèªã®æŠå¿µã¯ãã®ãããªã¢ãããŒããæäŸããŠããŸããããããããã¹ããŒããã€ã³ã¿ãŒã䜿çšããŠæš¡å£ããããšãã§ããŸãã
ä»æ¥ãC ++ã«ã¯ãããã«äœ¿ããããšåŒã°ããæŠåšåº«ã«ã¹ããŒããã€ã³ã¿ãŒããããŸãïŒC ++ 17æšæºã¯æ¢ã«ããã€ãã®å€ãã¿ã€ãã®ã¹ããŒããã€ã³ã¿ãŒã®èšèªãåãé€ãããšã«æåããŠããŸãïŒããããã¯åžžã«ããã§ã¯ãããŸããã 0.9ãšçªå·ä»ããããOSGã®å ¬åŒããŒãžã§ã³ã®æåã®ãã®ã¯2002幎ã«èªçããæåã®å ¬åŒãªãªãŒã¹ãŸã§ããã«3幎ããããŸããã ãã®æç¹ã§ã¯ãC ++æšæºã¯ãŸã ã¹ããŒããã€ã³ã¿ãŒãæäŸããŠããŸããã§ããã æŽå²çãªäœè«ã1ã€ä¿¡ãããšããŠããèšèªèªäœã¯èŠåŽããŠããŸããã ãã®ãããOSGã«å®è£ ãããŠããç¬èªã®ã¹ããŒããã€ã³ã¿ãŒã®åœ¢ã®èªè»¢è»ã®å€èŠ³ã¯ãé©ãããšã§ã¯ãããŸããã ãã®ã¡ã«ããºã ã¯ãšã³ãžã³ã®æ§é ã«æ·±ãçµ±åãããŠãããããæåãããã®åäœãç解ããããšã絶察ã«å¿ èŠã§ãã
3. osg :: ref_ptr <>ããã³osg ::åç §ã¯ã©ã¹
OSGã¯ãosg :: ref_ptr <>ãã³ãã¬ãŒãã¯ã©ã¹ã«åºã¥ããŠç¬èªã®ã¹ããŒããã€ã³ã¿ãŒã¡ã«ããºã ãæäŸããèªåã¬ããŒãžã³ã¬ã¯ã·ã§ã³ãå®è£ ããŸãã OSGã¯ãé©åãªæäœã®ããã«ãåç §ã«ãŠã³ããäœæãããã¡ã¢ãªãããã¯ã管çããããã®å¥ã®osg :: Referencedã¯ã©ã¹ãæäŸããŸãã
osg :: ref_ptr <>ã¯ã©ã¹ã¯ãããã€ãã®æŒç®åãšã¡ãœãããæäŸããŸãã
- getïŒïŒã¯ãçã®ãã€ã³ã¿ãè¿ããããªãã¯ã¡ãœããã§ããããšãã°ãosg :: Nodeãã³ãã¬ãŒããåŒæ°ãšããŠäœ¿çšãããšããã®ã¡ãœããã¯osg :: Node *ãè¿ããŸãã
- operator *ïŒïŒã¯å®éã«ã¯éåç
§æŒç®åã§ãã
- operator->ïŒïŒããã³operator =ïŒïŒ-ãã®ãã€ã³ã¿ãŒã«ãã£ãŠèšè¿°ããããªããžã§ã¯ãã®ã¡ãœãããšããããã£ã«ã¢ã¯ã»ã¹ãããšãã«ãosg :: ref_ptr <>ãå€å
žçãªãã€ã³ã¿ãŒãšããŠäœ¿çšã§ããŸãã
- operator ==ïŒïŒãoperatorïŒ=ïŒïŒããã³operatorïŒïŒïŒ-ã¹ããŒããã€ã³ã¿ãŒã§æ¯èŒæäœãå®è¡ã§ããŸãã
- validïŒïŒã¯ããããŒãžãã€ã³ã¿ãŒã«æå¹ãªå€ïŒNULLã§ã¯ãªãïŒãããå Žåã«trueãè¿ããããªãã¯ã¡ãœããã§ãã åŒsome_ptr.validïŒïŒã¯ãsome_ptrãã¹ããŒããã€ã³ã¿ãŒã®å ŽåãåŒsome_ptrïŒ= NULLãšåçã§ãã
- releaseïŒïŒã¯ãããªãã¯é¢æ°ã§ãããé¢æ°ãã管çã¢ãã¬ã¹ãè¿ãããå Žåã«äŸ¿å©ã§ãã ããã«ã€ããŠã¯åŸã§è©³ãã説æããŸãã
osg :: Referencedã¯ã©ã¹ã¯ãããŒãããžãªã¡ããªãã¬ã³ããªã³ã°ç¶æ ãã¹ããŒãžã«é 眮ãããä»ã®ãªããžã§ã¯ããªã©ãã·ãŒã³ã°ã©ãã®ãã¹ãŠã®èŠçŽ ã®åºæ¬ã¯ã©ã¹ã§ãã ãããã£ãŠãã·ãŒã³ã®ã«ãŒãããŒããäœæããŠãosg :: Referencedã¯ã©ã¹ã«ãã£ãŠæäŸããããã¹ãŠã®æ©èœãéæ¥çã«ç¶æ¿ããŸãã ãããã£ãŠãç§ãã¡ã®ããã°ã©ã ã«ã¯çºè¡šããããŸã
osg::ref_ptr<osg::Node> root;
osg :: Referencedã¯ã©ã¹ã«ã¯ãå²ãåœãŠãããã¡ã¢ãªãããã¯ãžã®åç §çšã®æŽæ°ã«ãŠã³ã¿ãŒãå«ãŸããŠããŸãã ãã®ã«ãŠã³ã¿ãŒã¯ãã¯ã©ã¹ã³ã³ã¹ãã©ã¯ã¿ãŒã§ãŒãã«åæåãããŸãã osg :: ref_ptr <>ãªããžã§ã¯ããäœæããããšã1ãã€å¢å ããŸãã ãã®ãã€ã³ã¿ãŒã¯ããã®ãã€ã³ã¿ãŒã«ãã£ãŠèšè¿°ããããªããžã§ã¯ããžã®åç §ãåé€ããããšããã«æžå°ããŸãã ãªããžã§ã¯ãã¯ãã¹ããŒããã€ã³ã¿ãŒãåç §ãåæ¢ãããšèªåçã«ç Žæ£ãããŸãã
osg :: Referencedã¯ã©ã¹ã«ã¯ã3ã€ã®ãããªãã¯ã¡ãœããããããŸãã
- refïŒïŒã¯ã1åç
§ã«ãŠã³ããã€å¢å ãããããªãã¯ã¡ãœããã§ãã
- unrefïŒïŒã¯ãããªãã¯ã¡ãœããã§ããã1åç
§ã«ãŠã³ããã€æžå°ããŸãã
- referenceCountïŒïŒã¯ãåç
§ã«ãŠã³ã¿ãŒã®çŸåšã®å€ãè¿ããããªãã¯ã¡ãœããã§ããããã¯ãã³ãŒãã®ãããã°æã«åœ¹ç«ã¡ãŸãã
ãããã®ã¡ãœããã¯ãosg :: Referencedãã掟çãããã¹ãŠã®ã¯ã©ã¹ã§äœ¿çšã§ããŸãã ãã ãããªã³ã¯ã«ãŠã³ã¿ãŒãæåã§å¶åŸ¡ãããšäºæž¬ã§ããªãçµæãçããå¯èœæ§ãããããšãèŠããŠããå¿ èŠããããŸãã
4. OSGãã¬ããŒãžãåéããæ¹æ³ãšãã®çç±
ã¹ããŒããã€ã³ã¿ãŒãšã¬ããŒãžã³ã¬ã¯ã·ã§ã³ã䜿çšããçç±ã¯ããã€ããããŸãã
- é倧ãªãšã©ãŒã®æå°åïŒã¹ããŒããã€ã³ã¿ãŒã䜿çšãããšãã¡ã¢ãªã®å²ãåœãŠãšè§£æŸãèªååã§ããŸãã å±éºãªçã®ãã€ã³ã¿ã¯ãããŸããã
- å¹æçãªã¡ã¢ãªç®¡çïŒãªããžã§ã¯ãã«å²ãåœãŠãããã¡ã¢ãªã¯ããªããžã§ã¯ããäžèŠã«ãªããšããã«è§£æŸãããã·ã¹ãã ãªãœãŒã¹ã®çµæžçãªäœ¿çšã«ã€ãªãããŸãã
- ã¢ããªã±ãŒã·ã§ã³ã®ãããã°ã®ä¿é²ïŒãªããžã§ã¯ããžã®ãªã³ã¯ã®æ°ãæ確ã«è¿œè·¡ããæ©èœãåããŠãããããããŸããŸãªçš®é¡ã®æé©åãšå®éšã®æ©äŒããããŸãã
ã·ãŒã³ã°ã©ããã«ãŒãããŒããšããã€ãã®ã¬ãã«ã®åããŒãã§æ§æãããŠãããšä»®å®ããŸãã ã«ãŒãããŒããšãã¹ãŠã®åããŒããosg :: ref_ptr <>ã¯ã©ã¹ã䜿çšããŠç®¡çãããŠããå Žåãã¢ããªã±ãŒã·ã§ã³ã¯ã«ãŒãããŒããžã®ãã€ã³ã¿ãŒã®ã¿ã远跡ã§ããŸãã ãã®ããŒããåé€ãããšããã¹ãŠã®åããŒããé 次èªåçã«åé€ãããŸãã
ã¹ããŒããã€ã³ã¿ãŒã¯ãããŒã«ã«å€æ°ãã°ããŒãã«å€æ°ãã¯ã©ã¹ã¡ã³ããŒãšããŠäœ¿çšã§ããã¹ããŒããã€ã³ã¿ãŒãç¯å²å€ã«ãªããšèªåçã«åç §ã«ãŠã³ããæžãããŸãã
OSGéçºè ã¯ãã¹ããŒããã€ã³ã¿ãŒããããžã§ã¯ãã§äœ¿çšããããšã匷ããå§ãããŸããã泚æãã¹ãåºæ¬çãªãã€ã³ããããã€ããããŸãã
- osgã®ã€ã³ã¹ã¿ã³ã¹::åç
§ããã³ãã®æŽŸçç©ã¯ãããŒãäžã§ã®ã¿äœæã§ããŸãã ãããã®ã¯ã©ã¹ã®ãã¹ãã©ã¯ã¿ã¯ä¿è·ãããŠãããšå®£èšãããŠãããããã¹ã¿ãã¯äžã«ããŒã«ã«å€æ°ãšããŠäœæããããšã¯ã§ããŸããã äŸãã°
osg::ref_ptr<osg::Node> node = new osg::Node; // osg::Node node; //
- éåžžã®C ++ãã€ã³ã¿ãŒã䜿çšããŠäžæçãªã·ãŒã³ããŒããäœæã§ããŸããããã®ã¢ãããŒãã¯å®å
šã§ã¯ãããŸããã ã·ãŒã³ã°ã©ããæ£ãã管çãããããã«ãã¹ããŒããã€ã³ã¿ãŒã䜿çšããããšããå§ãããŸãã
osg::Node *tmpNode = new osg::Node; // , ... osg::ref_ptr<osg::Node> node = tmpNode; // !
- ããŒããããèªäœãçŽæ¥ãŸãã¯éæ¥çã«è€æ°ã®ã¬ãã«ã§åç
§ããå ŽåãããªãŒã§åŸªç°ãªã³ã¯ã·ãŒã³ã䜿çšããªãã§ãã ãã
ã·ãŒã³ã°ã©ãã®ãµã³ãã«ã°ã©ãã§ã¯ãChild 1.1ããŒãã¯ããèªäœãæããChild 2.2ããŒãã¯Child 1.2ããŒããæããŸãã ãã®ãããªçš®é¡ã®ãªã³ã¯ã¯ããªã³ã¯æ°ã®èª€ã£ãèšç®ãšããã°ã©ã ã®äžæ確ãªåäœã«ã€ãªããå¯èœæ§ããããŸãã
5.管ç察象ãªããžã§ã¯ãã®è¿œè·¡
OSGã®ã¹ããŒããã€ã³ã¿ãŒã¡ã«ããºã ã®åäœã説æããããã«ã次ã®åæäŸãäœæããŸãã
main.h
#ifndef MAIN_H #define MAIN_H #include <osg/ref_ptr> #include <osg/Referenced> #include <iostream> #endif // MAIN_H
main.cpp
#include "main.h" class MonitoringTarget : public osg::Referenced { public: MonitoringTarget(int id) : _id(id) { std::cout << "Constructing target " << _id << std::endl; } protected: virtual ~MonitoringTarget() { std::cout << "Dsetroying target " << _id << std::endl; } int _id; }; int main(int argc, char *argv[]) { (void) argc; (void) argv; osg::ref_ptr<MonitoringTarget> target = new MonitoringTarget(0); std::cout << "Referenced count before referring: " << target->referenceCount() << std::endl; osg::ref_ptr<MonitoringTarget> anotherTarget = target; std::cout << "Referenced count after referring: " << target->referenceCount() << std::endl; return 0; }
osg ::åç §ãããåå«ã¯ã©ã¹ãäœæããŸããããã¯ãã€ã³ã¹ã¿ã³ã¹ãäœæãããããšãå ±åããã€ã³ã¹ã¿ã³ã¹ã®äœææã«æ±ºå®ãããèå¥åã衚瀺ããã³ã³ã¹ãã©ã¯ã¿ãšãã¹ãã©ã¯ã¿ä»¥å€ã§ã¯äœãè¡ããŸããã ã¹ããŒããã€ã³ã¿ãŒã¡ã«ããºã ã䜿çšããŠã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ãäœæãã
osg::ref_ptr<MonitoringTarget> target = new MonitoringTarget(0);
次ã«ãã¿ãŒã²ãããªããžã§ã¯ãã®åç §ã«ãŠã³ã¿ãŒã衚瀺ããŸã
std::cout << "Referenced count before referring: " << target->referenceCount() << std::endl;
ãã®åŸãæ°ããã¹ããŒããã€ã³ã¿ãŒãäœæããåã®ãã€ã³ã¿ãŒã®å€ãå²ãåœãŠãŸã
osg::ref_ptr<MonitoringTarget> anotherTarget = target;
ãããŠåã³åç §ã«ãŠã³ã¿ãŒã衚瀺ããŸã
std::cout << "Referenced count after referring: " << target->referenceCount() << std::endl;
ããã°ã©ã ã®åºåãåæããŠåŸããã®ãèŠãŠã¿ãŸããã
15:42:39: Constructing target 0 Referenced count before referring: 1 Referenced count after referring: 2 Dsetroying target 0 15:42:42:
ã¯ã©ã¹ã³ã³ã¹ãã©ã¯ã¿ãŒãèµ·åãããšã察å¿ããã¡ãã»ãŒãžã衚瀺ããããªããžã§ã¯ãã®ã¡ã¢ãªãå²ãåœãŠãããã³ã³ã¹ãã©ã¯ã¿ãŒãæ£åžžã«æ©èœããããšãéç¥ãããŸãã ããã«ãã¹ããŒããã€ã³ã¿ãŒãäœæããåŸãäœæããããªããžã§ã¯ãã®åç §ã«ãŠã³ã¿ãŒã1ã€å¢ããŠããããšãããããŸãã æ°ãããã€ã³ã¿ãŒãäœæããå€ããã€ã³ã¿ãŒã®å€ãå²ãåœãŠãŸã-åºæ¬çã«åããªããžã§ã¯ããžã®æ°ãããªã³ã¯ãäœæãããããåç §ã«ãŠã³ã¿ãŒã¯ãã1ã€å¢å ããŸãã ããã°ã©ã ãçµäºãããšãMonitoringTargetã¯ã©ã¹ã®ãã¹ãã©ã¯ã¿ãåŒã³åºãããŸãã
ãã®ãããªã³ãŒããmainïŒïŒé¢æ°ã®æåŸã«è¿œå ããŠãå¥ã®å®éšãè¡ã£ãŠã¿ãŸãããã
for (int i = 1; i < 5; i++) { osg::ref_ptr<MonitoringTarget> subTarget = new MonitoringTarget(i); }
ãã®ãããªãææ°ãããã°ã©ã ã«ã€ãªãã
16:04:30: Constructing target 0 Referenced count before referring: 1 Referenced count after referring: 2 Constructing target 1 Dsetroying target 1 Constructing target 2 Dsetroying target 2 Constructing target 3 Dsetroying target 3 Constructing target 4 Dsetroying target 4 Dsetroying target 0 16:04:32:
ã¹ããŒããã€ã³ã¿ãŒã䜿çšããŠãã«ãŒãã®æ¬äœã«ããã€ãã®ãªããžã§ã¯ããäœæããŸãã ãã®å Žåããã€ã³ã¿ã®ã¹ã³ãŒãã¯ã«ãŒãã®æ¬äœã®ã¿ã«æ¡åŒµããããããçµäºãããšããã¹ãã©ã¯ã¿ãèªåçã«åŒã³åºãããŸãã ããã¯èµ·ãããŸãããåœç¶ã®ããšã§ãããéåžžã®ãã€ã³ã¿ãŒã䜿çšããŸãã
ã¡ã¢ãªã®èªå解æŸã¯ãã¹ããŒããã€ã³ã¿ãŒãæäœãããã1ã€ã®éèŠãªæ©èœã§ãã osg ::åç §ããã掟çã¯ã©ã¹ã®ãã¹ãã©ã¯ã¿ã¯ä¿è·ãããŠããããããªããžã§ã¯ããåé€ããããã«æ瀺çã«åé€æŒç®åãåŒã³åºãããšã¯ã§ããŸããã ãªããžã§ã¯ããåé€ããå¯äžã®æ¹æ³ã¯ããªããžã§ã¯ããžã®ãªã³ã¯ã®æ°ããªã»ããããããšã§ãã ãããããã®åŸããã«ãã¹ã¬ããããŒã¿åŠçäžã«ã³ãŒããå®å šã§ãªããªããŸã-å¥ã®ã¹ã¬ããããæ¢ã«åé€ããããªããžã§ã¯ãã«ã¢ã¯ã»ã¹ã§ããŸãã
幞ããªããšã«ãOSGã¯ããªããžã§ã¯ãåé€ã¹ã±ãžã¥ãŒã©ã䜿çšããŠããã®åé¡ã®è§£æ±ºçãæäŸããŸãã ãã®ã¹ã±ãžã¥ãŒã©ã¯ãosg :: DeleteHandlerã¯ã©ã¹ã®äœ¿çšã«åºã¥ããŠããŸãã ãªããžã§ã¯ããããã«åé€ããæäœãå®è¡ããã®ã§ã¯ãªãããã°ããããŠããå®è¡ããããã«æ©èœããŸãã åé€ãããã¹ãŠã®ãªããžã§ã¯ãã¯ãå®å šãªåé€ã®ç¬éãæ¥ããŸã§äžæçã«ä¿åããããã®åŸããã«ãã¹ãŠåé€ãããŸãã osg :: DeleteHandleråé€ã¹ã±ãžã¥ãŒã©ãŒã¯ãOSGã¬ã³ããŒããã¯ãšã³ãã«ãã£ãŠå¶åŸ¡ãããŸãã
6.é¢æ°ããæ»ã
ãµã³ãã«ã³ãŒãã«æ¬¡ã®é¢æ°ãè¿œå ããŸã
MonitoringTarget *createMonitoringTarget(int id) { osg::ref_ptr<MonitoringTarget> target = new MonitoringTarget(id); return target.release(); }
ã«ãŒãå ã®æ°ããæŒç®åã®åŒã³åºãããã®é¢æ°ã®åŒã³åºãã«çœ®ãæããŸã
for (int i = 1; i < 5; i++) { osg::ref_ptr<MonitoringTarget> subTarget = createMonitoringTarget(i); }
releaseïŒïŒãåŒã³åºããšããªããžã§ã¯ããžã®åç §ã®æ°ããŒãã«æžããŸãããã¡ã¢ãªãåé€ãã代ããã«ãå²ãåœãŠãããã¡ã¢ãªãžã®å®éã®ãã€ã³ã¿ãçŽæ¥è¿ããŸãã ãã®ãã€ã³ã¿ãŒãå¥ã®ã¹ããŒããã€ã³ã¿ãŒã«å²ãåœãŠãããŠããå Žåãã¡ã¢ãªãªãŒã¯ã¯çºçããŸããã
çµè«
ã·ãŒã³ã°ã©ããšã¹ããŒããã€ã³ã¿ãŒã®æŠå¿µã¯ãæäœã®åçããããã£ãŠOpenSceneGraphã®å¹æçãªäœ¿çšãç解ããããã®åºæ¬ã§ãã OSGã¹ããŒããã€ã³ã¿ãŒã«é¢ããŠã¯ã次ã®å Žåã«ãã®äœ¿çšã絶察ã«äžå¯æ¬ ã§ããããšãå¿ããªãã§ãã ããã
- ãªããžã§ã¯ãã®é·æä¿ç®¡ãæ³å®ãããŠããŸã
- ãããªããžã§ã¯ãã¯å¥ã®ãªããžã§ã¯ããžã®ãªã³ã¯ãä¿åããŸã
- é¢æ°ãããã€ã³ã¿ãŒãè¿ãå¿ èŠããããŸã
ãã®èšäºã§æäŸãããŠãããµã³ãã«ã³ãŒãã¯ã ããããå ¥æã§ããŸã ã
ç¶ç¶ããã«ã¯...