@@ -152,6 +152,8 @@ static public File getBuildFolder() {
152152
153153 static public PreferencesMap getBoardPreferences () {
154154 TargetBoard board = getTargetBoard ();
155+ if (board == null )
156+ return null ;
155157
156158 PreferencesMap prefs = new PreferencesMap (board .getPreferences ());
157159 for (String menuId : board .getMenuIds ()) {
@@ -343,8 +345,11 @@ static public String getSketchbookPath() {
343345 }
344346
345347 public static TargetBoard getTargetBoard () {
348+ TargetPlatform targetPlatform = getTargetPlatform ();
349+ if (targetPlatform == null )
350+ return null ;
346351 String boardId = PreferencesData .get ("board" );
347- return getTargetPlatform () .getBoard (boardId );
352+ return targetPlatform .getBoard (boardId );
348353 }
349354
350355 /**
@@ -669,28 +674,27 @@ static public void main(String args[]) throws Exception {
669674 }
670675
671676 static public void onBoardOrPortChange () {
672- TargetPlatform targetPlatform = getTargetPlatform ();
673- if (targetPlatform == null )
674- return ;
675-
676- // Calculate paths for libraries and examples
677677 examplesFolder = getContentFile ("examples" );
678678 toolsFolder = getContentFile ("tools" );
679-
680- File platformFolder = targetPlatform .getFolder ();
681679 librariesFolders = new ArrayList <File >();
682680 librariesFolders .add (getContentFile ("libraries" ));
683- String core = getBoardPreferences ().get ("build.core" );
684- if (core .contains (":" )) {
685- String referencedCore = core .split (":" )[0 ];
686- TargetPlatform referencedPlatform = getTargetPlatform (referencedCore , targetPlatform .getId ());
687- if (referencedPlatform != null ) {
688- File referencedPlatformFolder = referencedPlatform .getFolder ();
689- librariesFolders .add (new File (referencedPlatformFolder , "libraries" ));
681+
682+ // Add library folder for the current selected platform
683+ TargetPlatform targetPlatform = getTargetPlatform ();
684+ if (targetPlatform != null ) {
685+ String core = getBoardPreferences ().get ("build.core" );
686+ if (core .contains (":" )) {
687+ String referencedCore = core .split (":" )[0 ];
688+ TargetPlatform referencedPlatform = getTargetPlatform (referencedCore , targetPlatform .getId ());
689+ if (referencedPlatform != null ) {
690+ File referencedPlatformFolder = referencedPlatform .getFolder ();
691+ librariesFolders .add (new File (referencedPlatformFolder , "libraries" ));
692+ }
690693 }
694+ File platformFolder = targetPlatform .getFolder ();
695+ librariesFolders .add (new File (platformFolder , "libraries" ));
696+ librariesFolders .add (getSketchbookLibrariesFolder ());
691697 }
692- librariesFolders .add (new File (platformFolder , "libraries" ));
693- librariesFolders .add (getSketchbookLibrariesFolder ());
694698
695699 // Scan for libraries in each library folder.
696700 // Libraries located in the latest folders on the list can override
0 commit comments