0

I am trying to load a simple TMX Tiled Map that I made using Tiled application into Visual Studio. But I am getting this error:

????????????
????????
'TaskHost.exe' (Win32): Loaded 'C:\Windows\System32\StorageProxy.dll'. Cannot find or open the PDB file.
'TaskHost.exe' (Win32): Loaded 'C:\Windows\System32\Windows.Phone.Storage.dll'. Cannot find or open the PDB file.
'TaskHost.exe' (Win32): Loaded 'C:\Windows\System32\PhotosAPI.dll'. Cannot find or open the PDB file.
'TaskHost.exe' (Win32): Loaded 'C:\Windows\System32\PhotosServiceClient.dll'. Cannot find or open the PDB file.
First-chance exception at 0x676D0BFB (libcocos2d_v3.3_WindowsPhone_8.0.dll) in TaskHost.exe: 0xC0000005: Access violation reading location 0x00000178.
Unhandled exception at 0x676D0BFB (libcocos2d_v3.3_WindowsPhone_8.0.dll) in TaskHost.exe: 0xC0000005: Access violation reading location 0x00000178.

The program '[4760] TaskHost.exe' has exited with code 0 (0x0).

So I did a bit of digging and found out that this was a bug when your resources are not in the same directory as the TMX file and was a bug which was eventually fixed as per this link

http://discuss.cocos2d-x.org/t/cocos2d-x-v3-tilemap-image-source-path/8315

I am using Cocos 2d-x V3.3

Here is the code that I am using in my init() function of my MainScene

bool MainScene::init()
{
    if (!Layer::init())
    {
        return false;
    }
...

auto tmxMap = TMXTiledMap::create("TMX/test-tiled-map.tmx");
    this->addChild(tmxMap);

...

    return true;
}

Also my tile resources belong to the same place as my .tmx file. i.e. the Assets/Resources/TMX/ Folder

Here is my .tmx File:

    <?xml version="1.0" encoding="UTF-8"?>
    <map version="1.0" orientation="orthogonal" renderorder="right-down" width="41" height="41" tilewidth="35" tileheight="35" nextobjectid="1">
     <tileset firstgid="1" name="OriginMap" tilewidth="35" tileheight="35">
  <tile id="0">
   <image width="35" height="35" source="water.png"/>
  </tile>
  <tile id="1">
   <image width="35" height="35" source="water-bot.png"/>
  </tile>
  <tile id="2">
   <image width="35" height="35" source="water-bot-left.png"/>
  </tile>
  <tile id="3">
   <image width="35" height="35" source="water-bot-right.png"/>
  </tile>
  <tile id="4">
   <image width="35" height="35" source="water-left.png"/>
  </tile>
  <tile id="5">
   <image width="35" height="35" source="water-right.png"/>
  </tile>
  <tile id="6">
   <image width="35" height="35" source="water-top.png"/>
  </tile>
  <tile id="7">
   <image width="35" height="35" source="water-top-left.png"/>
  </tile>
  <tile id="8">
   <image width="35" height="35" source="water-top-right.png"/>
  </tile>
 </tileset>
     <layer name="Tile Layer 1" width="41" height="41">
      <data>
       <tile gid="1"/>
       <tile gid="1"/>
       <tile gid="1"/>
       <tile gid="1"/>
       <tile gid="1"/>
    ... (lots of tiles of water) ...
       <tile gid="1"/>
       <tile gid="1"/>
      </data>
     </layer>
    </map>

Generated Call Stack by Visual Studio:

>   libcocos2d_v3.3_WindowsPhone_8.0.dll!cocos2d::Node::addChild(cocos2d::Node * child=0x00000000) Line 1065    C++
    EmpiresAtWarComponent.dll!MainScene::init() Line 94 C++
    EmpiresAtWarComponent.dll!MainScene::create() Line 18   C++
    EmpiresAtWarComponent.dll!MainScene::createScene() Line 9   C++
    EmpiresAtWarComponent.dll!AppDelegate::applicationDidFinishLaunching() Line 41  C++
    libcocos2d_v3.3_WindowsPhone_8.0.dll!cocos2d::Application::run() Line 77    C++
    EmpiresAtWarComponent.dll!Cocos2dRenderer::[DirectXBase]::CreateGLResources() Line 63   C++
    EmpiresAtWarComponent.dll!DirectXBase::UpdateDevice(ID3D11Device1 * device=0x005c7744, ID3D11DeviceContext1 * context=0x005c8820, ID3D11RenderTargetView * renderTargetView=0x03112a38) Line 110    C++
    EmpiresAtWarComponent.dll!cocos2d::Direct3DInterop::Draw(ID3D11Device1 * device=0x005c7744, ID3D11DeviceContext1 * context=0x005c8820, ID3D11RenderTargetView * renderTargetView=0x03112a38) Line 159   C++
    EmpiresAtWarComponent.dll!Direct3DContentProvider::Draw(ID3D11Device1 * device=0x005c7744, ID3D11DeviceContext1 * context=0x005c8820, ID3D11RenderTargetView * renderTargetView=0x03112a38) Line 64 C++
  • When you debug the app, you should see the line where it crashes. We need to see that line and the call stack. – CodeSmile Jan 30 '15 at 16:00
  • It generates a dialog box wait i ll just put it up! – Vasu Mahesh Jan 30 '15 at 16:01
  • nothing in the log? Like "file not found" or something like that? It sounds like the returned TMXTiledMap is nil, which means if there's nothing in the log indication a load failure (and what to do to resolve it) you will have to step through the code and find out where/why exactly it fails to create the TMX map node. – CodeSmile Jan 30 '15 at 16:08
  • The Debug Log says "Cannot find or open the PDB file" , but nothing related to TMX File? – Vasu Mahesh Jan 30 '15 at 16:11
  • Are you sure you are debugging the app? Try adding `assert(false);` in init, this should get VS to halt the app and show that line. If it just crashes or does ntohing then you aren't debugging, just running (or debugging a release build). – CodeSmile Jan 30 '15 at 16:13
  • Yes it just crashed :/ But my VS is set on Debug and that COCOS_DEBUG Variable is also 1 ... Also i can confirm i have done this: http://www.cocos2d-x.org/wiki/Windows_Phone_8_Installation_and_Setup – Vasu Mahesh Jan 30 '15 at 16:16
  • Edit: I am on Debugging mode i can put break points on the CPP files – Vasu Mahesh Jan 30 '15 at 16:24
  • Okay, I assumed that addChild with a null object would trigger an assert/exception in cocos2d, rather than an access violation. – CodeSmile Jan 30 '15 at 16:49
  • Also i can't add any breakpoints inside the implementation files of the `TMXTiledMap` Class so I am guessing its failing at the initWithFile mehtod of that class ... – Vasu Mahesh Jan 31 '15 at 05:07

1 Answers1

0

The Answer was simple...

When you Import your resources you have to set

"Copy if newer" as Value to your Resource Under the Section "Copy to Output Directory" ... Doing that the file gets copied to your build otherwise it never reaches cocos. Hence the "Access Violation" ...

http://www.cocos2d-x.org/news/78

this link is very old as per VS 2014 . It says

The solution is very simple, that is to set the resource file Content field >to “ Yes” , the Item type field to “Does not participate in build”.

which wasn't the case for me. Hope it helps any other Cocos starter with the issue ! :)